99use Illuminate \Database \Eloquent \Builder ;
1010use Illuminate \Database \Eloquent \Model ;
1111use Tmilos \ScimFilterParser \Ast \AttributePath ;
12- use Tmilos \ScimFilterParser \Ast \ComparisonExpression ;
13- use Tmilos \ScimSchema \Model \Resource ;
12+ use Illuminate \Support \Str ;
1413
1514class Attribute
1615{
@@ -36,7 +35,7 @@ class Attribute
3635
3736 protected $ multiValued = false ;
3837 protected $ mutability = 'readWrite ' ;
39- protected $ type = ' string ' ;
38+ protected $ type ;
4039 protected $ description = null ;
4140 protected $ defaultValue = null ;
4241 protected $ returned = 'default ' ;
@@ -64,10 +63,11 @@ public function getValidations()
6463 /**
6564 * Return SCIM schema for this attribute
6665 */
67- public function generateSchema (){
66+ public function generateSchema ()
67+ {
6868 return [
6969 'name ' => $ this ->name ,
70- 'type ' => $ this ->type ,
70+ 'type ' => $ this ->getType () ,
7171 'mutability ' => $ this ->mutability ,
7272 'returned ' => $ this ->returned ,
7373 'uniqueness ' => 'server ' ,
@@ -103,7 +103,8 @@ public function ensure(...$validations)
103103 return $ this ;
104104 }
105105
106- public function default ($ value ){
106+ public function default ($ value )
107+ {
107108 $ this ->defaultValue = $ value ;
108109
109110 return $ this ;
@@ -119,6 +120,23 @@ public function nullable()
119120 return in_array ('nullable ' , $ this ->validations );
120121 }
121122
123+ public function getType ()
124+ {
125+ $ result = $ this ->type ;
126+
127+ if ($ result == null ) {
128+ if (in_array ('boolean ' , $ this ->validations )) {
129+ $ result = 'boolean ' ;
130+ } elseif (in_array ('integer ' , $ this ->validations )) {
131+ $ result = 'integer ' ;
132+ } else {
133+ $ result = 'string ' ;
134+ }
135+ }
136+
137+ return $ result ;
138+ }
139+
122140 public function isReadSupported ()
123141 {
124142 return $ this ->readEnabled ;
@@ -134,7 +152,8 @@ public function shouldReturn(&$object)
134152 return true ;
135153 }
136154
137- public function setReturned ($ returned ){
155+ public function setReturned ($ returned )
156+ {
138157 $ this ->returned = $ returned ;
139158 return $ this ;
140159 }
@@ -145,7 +164,8 @@ public function setParent($parent)
145164 return $ this ;
146165 }
147166
148- protected function isRequested ($ attributes ){
167+ protected function isRequested ($ attributes )
168+ {
149169 return empty ($ attributes ) || in_array ($ this ->name , $ attributes ) || in_array ($ this ->getFullKey (), $ attributes ) || ($ this ->parent != null && $ this ->parent ->isRequested ($ attributes ));
150170 }
151171
@@ -156,7 +176,7 @@ public function read(&$object, array $attributes = []): ?AttributeValue
156176 return null ;
157177 }
158178
159- if ($ this ->returned == 'never ' ){
179+ if ($ this ->returned == 'never ' ) {
160180 return null ;
161181 }
162182
0 commit comments