| @@ -61,11 +61,11 @@ discard block | ||
| 61 | 61 | */ | 
| 62 | 62 | public function initAnnotation(array $properties) | 
| 63 | 63 |      { | 
| 64 | - if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) | |
| 64 | + if (count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) | |
| 65 | 65 |          { | 
| 66 | 66 |              throw new AnnotationException('The @databag annotation requires a property "name" of type string'); | 
| 67 | 67 | } | 
| 68 | - if(!$this->validateDataBagName($properties['name'])) | |
| 68 | + if (!$this->validateDataBagName($properties['name'])) | |
| 69 | 69 |          { | 
| 70 | 70 | throw new AnnotationException($properties['name'] . ' is not a valid "name" value for the @databag annotation'); | 
| 71 | 71 | } | 
| @@ -85,7 +85,7 @@ discard block | ||
| 85 | 85 | */ | 
| 86 | 86 | public function getValue() | 
| 87 | 87 |      { | 
| 88 | - if(is_array($this->xPrevValue)) | |
| 88 | + if (is_array($this->xPrevValue)) | |
| 89 | 89 |          { | 
| 90 | 90 | $this->xPrevValue[] = $this->sName; // Append the current value to the array | 
| 91 | 91 | return $this->xPrevValue; | 
| @@ -57,7 +57,7 @@ discard block | ||
| 57 | 57 | public static function parseAnnotation($value) | 
| 58 | 58 |      { | 
| 59 | 59 |          $aParams = preg_split("/[\s]+/", $value, 2); | 
| 60 | - if(count($aParams) === 1) | |
| 60 | + if (count($aParams) === 1) | |
| 61 | 61 |          { | 
| 62 | 62 | return ['call' => rtrim($aParams[0])]; | 
| 63 | 63 | } | 
| @@ -81,28 +81,28 @@ discard block | ||
| 81 | 81 | */ | 
| 82 | 82 | public function initAnnotation(array $properties) | 
| 83 | 83 |      { | 
| 84 | - if(!isset($properties['call']) || !is_string($properties['call'])) | |
| 84 | + if (!isset($properties['call']) || !is_string($properties['call'])) | |
| 85 | 85 |          { | 
| 86 | 86 |              throw new AnnotationException('The @' . $this->getType() . | 
| 87 | 87 | ' annotation requires a property "call" of type string'); | 
| 88 | 88 | } | 
| 89 | - if(!$this->validateMethodName($properties['call'])) | |
| 89 | + if (!$this->validateMethodName($properties['call'])) | |
| 90 | 90 |          { | 
| 91 | 91 | throw new AnnotationException($properties['call'] . | 
| 92 | 92 | ' is not a valid "call" value for the @' . $this->getType() . ' annotation'); | 
| 93 | 93 | } | 
| 94 | - foreach(array_keys($properties) as $propName) | |
| 94 | + foreach (array_keys($properties) as $propName) | |
| 95 | 95 |          { | 
| 96 | - if($propName !== 'call' && $propName !== 'with') | |
| 96 | + if ($propName !== 'call' && $propName !== 'with') | |
| 97 | 97 |              { | 
| 98 | 98 |                  throw new AnnotationException('Unknown property "' . $propName . | 
| 99 | 99 | '" in the @' . $this->getType() . ' annotation'); | 
| 100 | 100 | } | 
| 101 | 101 | } | 
| 102 | 102 | // Cannot use isset here, because it will return false in case $properties['with'] === null | 
| 103 | -        if(array_key_exists('with', $properties)) | |
| 103 | +        if (array_key_exists('with', $properties)) | |
| 104 | 104 |          { | 
| 105 | - if(!is_array($properties['with'])) | |
| 105 | + if (!is_array($properties['with'])) | |
| 106 | 106 |              { | 
| 107 | 107 |                  throw new AnnotationException('The "with" property of the @' . | 
| 108 | 108 | $this->getType() . ' annotation must be of type array'); | 
| @@ -117,7 +117,7 @@ discard block | ||
| 117 | 117 | */ | 
| 118 | 118 | public function getValue() | 
| 119 | 119 |      { | 
| 120 | - if(is_array($this->xPrevValue)) | |
| 120 | + if (is_array($this->xPrevValue)) | |
| 121 | 121 |          { | 
| 122 | 122 | // Add the current value to the array | 
| 123 | 123 | $this->xPrevValue[$this->sMethodName] = $this->sMethodParams; | 
| @@ -38,11 +38,11 @@ discard block | ||
| 38 | 38 | */ | 
| 39 | 39 | public static function parseAnnotation($value) | 
| 40 | 40 |      { | 
| 41 | - if($value === 'true') | |
| 41 | + if ($value === 'true') | |
| 42 | 42 |          { | 
| 43 | 43 | return [true]; | 
| 44 | 44 | } | 
| 45 | - if($value === 'false') | |
| 45 | + if ($value === 'false') | |
| 46 | 46 |          { | 
| 47 | 47 | return [false]; | 
| 48 | 48 | } | 
| @@ -55,7 +55,7 @@ discard block | ||
| 55 | 55 | */ | 
| 56 | 56 | public function initAnnotation(array $properties) | 
| 57 | 57 |      { | 
| 58 | - if(count($properties) !== 0 && | |
| 58 | + if (count($properties) !== 0 && | |
| 59 | 59 | (count($properties) !== 1 || !isset($properties[0]) || !is_bool($properties[0]))) | 
| 60 | 60 |          { | 
| 61 | 61 |              throw new AnnotationException('the @exclude annotation requires a single boolean or no property'); | 
| @@ -60,11 +60,11 @@ discard block | ||
| 60 | 60 | */ | 
| 61 | 61 | public function initAnnotation(array $properties) | 
| 62 | 62 |      { | 
| 63 | - if(count($properties) != 1 || !isset($properties['field']) || !is_string($properties['field'])) | |
| 63 | + if (count($properties) != 1 || !isset($properties['field']) || !is_string($properties['field'])) | |
| 64 | 64 |          { | 
| 65 | 65 |              throw new AnnotationException('The @upload annotation requires a property "field" of type string'); | 
| 66 | 66 | } | 
| 67 | - if(!$this->validateUploadField($properties['field'])) | |
| 67 | + if (!$this->validateUploadField($properties['field'])) | |
| 68 | 68 |          { | 
| 69 | 69 | throw new AnnotationException($properties['field'] . ' is not a valid "field" value for the @upload annotation'); | 
| 70 | 70 | } | 
| @@ -84,6 +84,6 @@ discard block | ||
| 84 | 84 | */ | 
| 85 | 85 | public function getValue() | 
| 86 | 86 |      { | 
| 87 | - return "'" . $this->sField . "'" ; // The field id is surrounded with simple quotes. | |
| 87 | + return "'" . $this->sField . "'"; // The field id is surrounded with simple quotes. | |
| 88 | 88 | } | 
| 89 | 89 | } | 
| @@ -134,7 +134,7 @@ discard block | ||
| 134 | 134 | */ | 
| 135 | 135 | private function getFullClassName(string $sClassName): string | 
| 136 | 136 |      { | 
| 137 | - return ltrim($this->xClassFile->resolveType($sClassName), '\\');; | |
| 137 | + return ltrim($this->xClassFile->resolveType($sClassName), '\\'); ; | |
| 138 | 138 | } | 
| 139 | 139 | |
| 140 | 140 | /** | 
| @@ -146,38 +146,38 @@ discard block | ||
| 146 | 146 | $value = $this->properties['__value__']; | 
| 147 | 147 |          $aParams = preg_split("/[\s]+/", $value, 3); | 
| 148 | 148 | $nParamCount = count($aParams); | 
| 149 | - if($nParamCount === 1) | |
| 149 | + if ($nParamCount === 1) | |
| 150 | 150 |          { | 
| 151 | 151 | // For a property, the only parameter is the class. Otherwise, it is the attribute. | 
| 152 | - if($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) | |
| 152 | + if ($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) | |
| 153 | 153 |              { | 
| 154 | - if(substr($aParams[0], 0, 1) === '$') | |
| 154 | + if (substr($aParams[0], 0, 1) === '$') | |
| 155 | 155 |                  { | 
| 156 | 156 |                      throw new AnnotationException('The only property of the @di annotation must be a class name'); | 
| 157 | 157 | } | 
| 158 | 158 | $this->sClass = $this->getFullClassName($aParams[0]); | 
| 159 | 159 | return; | 
| 160 | 160 | } | 
| 161 | - if(substr($aParams[0], 0, 1) !== '$') | |
| 161 | + if (substr($aParams[0], 0, 1) !== '$') | |
| 162 | 162 |              { | 
| 163 | 163 |                  throw new AnnotationException('The only property of the @di annotation must be a var name'); | 
| 164 | 164 | } | 
| 165 | 165 | $this->sAttr = substr($aParams[0], 1); | 
| 166 | 166 | return; | 
| 167 | 167 | } | 
| 168 | - if($nParamCount === 2) | |
| 168 | + if ($nParamCount === 2) | |
| 169 | 169 |          { | 
| 170 | 170 | // For a property, having 2 parameters is not allowed. | 
| 171 | - if($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) | |
| 171 | + if ($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) | |
| 172 | 172 |              { | 
| 173 | 173 |                  throw new AnnotationException('The @di annotation accepts only one property on a class attribute'); | 
| 174 | 174 | } | 
| 175 | 175 | |
| 176 | - if(substr($aParams[0], 0, 1) !== '$') | |
| 176 | + if (substr($aParams[0], 0, 1) !== '$') | |
| 177 | 177 |              { | 
| 178 | 178 |                  throw new AnnotationException('The only property of the @di annotation must be a var name'); | 
| 179 | 179 | } | 
| 180 | - if(substr($aParams[1], 0, 1) === '$') | |
| 180 | + if (substr($aParams[1], 0, 1) === '$') | |
| 181 | 181 |              { | 
| 182 | 182 |                  throw new AnnotationException('The first property of the @di annotation must be a class name'); | 
| 183 | 183 | } | 
| @@ -196,28 +196,28 @@ discard block | ||
| 196 | 196 | private function parseProperties() | 
| 197 | 197 |      { | 
| 198 | 198 | $nCount = count($this->properties); | 
| 199 | - if($nCount > 2 || | |
| 199 | + if ($nCount > 2 || | |
| 200 | 200 | ($nCount === 2 && !(isset($this->properties['attr']) && isset($this->properties['class']))) || | 
| 201 | 201 | ($nCount === 1 && !(isset($this->properties['attr']) || isset($this->properties['class'])))) | 
| 202 | 202 |          { | 
| 203 | 203 |              throw new AnnotationException('The @di annotation accepts only "attr" or "class" as properties'); | 
| 204 | 204 | } | 
| 205 | 205 | |
| 206 | - if(isset($this->properties['attr'])) | |
| 206 | + if (isset($this->properties['attr'])) | |
| 207 | 207 |          { | 
| 208 | - if($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) | |
| 208 | + if ($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) | |
| 209 | 209 |              { | 
| 210 | 210 |                  throw new AnnotationException('The @di annotation does not allow the "attr" property on class attributes'); | 
| 211 | 211 | } | 
| 212 | - if(!is_string($this->properties['attr'])) | |
| 212 | + if (!is_string($this->properties['attr'])) | |
| 213 | 213 |              { | 
| 214 | 214 |                  throw new AnnotationException('The @di annotation requires a property "attr" of type string'); | 
| 215 | 215 | } | 
| 216 | 216 | $this->sAttr = $this->properties['attr']; | 
| 217 | 217 | } | 
| 218 | - if(isset($this->properties['class'])) | |
| 218 | + if (isset($this->properties['class'])) | |
| 219 | 219 |          { | 
| 220 | - if(!is_string($this->properties['class'])) | |
| 220 | + if (!is_string($this->properties['class'])) | |
| 221 | 221 |              { | 
| 222 | 222 |                  throw new AnnotationException('The @di annotation requires a property "class" of type string'); | 
| 223 | 223 | } | 
| @@ -235,21 +235,21 @@ discard block | ||
| 235 | 235 | |
| 236 | 236 | // The type in the @di annotations can be set from the values in the @var annotations | 
| 237 | 237 | $aPropTypes = $this->xReader->getPropTypes(); | 
| 238 | - if($this->sClass === '' && isset($aPropTypes[$this->sAttr])) | |
| 238 | + if ($this->sClass === '' && isset($aPropTypes[$this->sAttr])) | |
| 239 | 239 |          { | 
| 240 | 240 | $this->sClass = ltrim($aPropTypes[$this->sAttr], '\\'); | 
| 241 | 241 | } | 
| 242 | 242 | |
| 243 | - if(!$this->validateAttrName($this->sAttr)) | |
| 243 | + if (!$this->validateAttrName($this->sAttr)) | |
| 244 | 244 |          { | 
| 245 | 245 | throw new AnnotationException($this->sAttr . ' is not a valid "attr" value for the @di annotation'); | 
| 246 | 246 | } | 
| 247 | - if(!$this->validateClassName($this->sClass)) | |
| 247 | + if (!$this->validateClassName($this->sClass)) | |
| 248 | 248 |          { | 
| 249 | 249 | throw new AnnotationException($this->sClass . ' is not a valid "class" value for the @di annotation'); | 
| 250 | 250 | } | 
| 251 | 251 | |
| 252 | - if(is_array($this->xPrevValue)) | |
| 252 | + if (is_array($this->xPrevValue)) | |
| 253 | 253 |          { | 
| 254 | 254 | $this->xPrevValue[$this->sAttr] = $this->sClass; // Append the current value to the array | 
| 255 | 255 | return $this->xPrevValue; | 
| @@ -139,10 +139,12 @@ discard block | ||
| 139 | 139 | $sName = $xAnnotation->getName(); | 
| 140 | 140 | $xAnnotation->setPrevValue($aAttributes[$sName] ?? null); | 
| 141 | 141 | $xValue = $xAnnotation->getValue(); | 
| 142 | - if($sName !== 'protected' || ($xValue)) // Ignore annotation @exclude with value false | |
| 142 | +            if($sName !== 'protected' || ($xValue)) { | |
| 143 | + // Ignore annotation @exclude with value false | |
| 143 | 144 |              { | 
| 144 | 145 | $aAttributes[$sName] = $xValue; | 
| 145 | 146 | } | 
| 147 | + } | |
| 146 | 148 | } | 
| 147 | 149 | return $aAttributes; | 
| 148 | 150 | } | 
| @@ -238,15 +240,13 @@ discard block | ||
| 238 | 240 | if(isset($aMethodAttrs['protected'])) | 
| 239 | 241 |                  { | 
| 240 | 242 | $aProtected[] = $sMethod; // The method is not to be exported. | 
| 241 | - } | |
| 242 | - elseif(count($aMethodAttrs) > 0) | |
| 243 | + } elseif(count($aMethodAttrs) > 0) | |
| 243 | 244 |                  { | 
| 244 | 245 | $aAttributes[$sMethod] = $aMethodAttrs; | 
| 245 | 246 | } | 
| 246 | 247 | } | 
| 247 | 248 | return [false, $aAttributes, $aProtected]; | 
| 248 | - } | |
| 249 | - catch(AnnotationException $e) | |
| 249 | + } catch(AnnotationException $e) | |
| 250 | 250 |          { | 
| 251 | 251 | throw new SetupException($e->getMessage()); | 
| 252 | 252 | } | 
| @@ -106,13 +106,13 @@ discard block | ||
| 106 | 106 | }); | 
| 107 | 107 | |
| 108 | 108 | $aAttributes = []; | 
| 109 | - foreach($aAnnotations as $xAnnotation) | |
| 109 | + foreach ($aAnnotations as $xAnnotation) | |
| 110 | 110 |          { | 
| 111 | 111 | $xAnnotation->setReader($this); | 
| 112 | 112 | $sName = $xAnnotation->getName(); | 
| 113 | 113 | $xAnnotation->setPrevValue($aAttributes[$sName] ?? null); | 
| 114 | 114 | $xValue = $xAnnotation->getValue(); | 
| 115 | - if($sName !== 'protected' || ($xValue)) // Ignore annotation @exclude with value false | |
| 115 | + if ($sName !== 'protected' || ($xValue)) // Ignore annotation @exclude with value false | |
| 116 | 116 |              { | 
| 117 | 117 | $aAttributes[$sName] = $xValue; | 
| 118 | 118 | } | 
| @@ -132,7 +132,7 @@ discard block | ||
| 132 | 132 | // Only keep the annotations declared in this package. | 
| 133 | 133 |          $aAnnotations = array_filter($aAnnotations, function($xAnnotation) use($sProperty) { | 
| 134 | 134 | // Save the property type | 
| 135 | - if(is_a($xAnnotation, VarAnnotation::class)) | |
| 135 | + if (is_a($xAnnotation, VarAnnotation::class)) | |
| 136 | 136 |              { | 
| 137 | 137 | $this->aPropTypes[$sProperty] = $xAnnotation->type; | 
| 138 | 138 | } | 
| @@ -141,11 +141,11 @@ discard block | ||
| 141 | 141 | }); | 
| 142 | 142 | |
| 143 | 143 | $nCount = count($aAnnotations); | 
| 144 | - if($nCount === 0) | |
| 144 | + if ($nCount === 0) | |
| 145 | 145 |          { | 
| 146 | 146 | return ['', null]; | 
| 147 | 147 | } | 
| 148 | - if($nCount > 1) | |
| 148 | + if ($nCount > 1) | |
| 149 | 149 |          { | 
| 150 | 150 |              throw new AnnotationException('Only one @di annotation is allowed on a property'); | 
| 151 | 151 | } | 
| @@ -176,10 +176,10 @@ discard block | ||
| 176 | 176 | $this->aPropTypes = []; | 
| 177 | 177 | $aPropAttrs = []; | 
| 178 | 178 | // Properties annotations | 
| 179 | - foreach($aProperties as $sProperty) | |
| 179 | + foreach ($aProperties as $sProperty) | |
| 180 | 180 |              { | 
| 181 | 181 | [$sName, $xValue] = $this->propAnnotations($sProperty, $this->xManager->getPropertyAnnotations($sClass, $sProperty)); | 
| 182 | - if($xValue !== null) | |
| 182 | + if ($xValue !== null) | |
| 183 | 183 |                  { | 
| 184 | 184 | $aPropAttrs[$sName] = array_merge($aPropAttrs[$sName] ?? [], $xValue); | 
| 185 | 185 | } | 
| @@ -189,13 +189,13 @@ discard block | ||
| 189 | 189 | $this->sMemberType = AnnotationManager::MEMBER_CLASS; | 
| 190 | 190 | |
| 191 | 191 | $aClassAttrs = $this->filterAnnotations($this->xManager->getClassAnnotations($sClass)); | 
| 192 | - if(isset($aClassAttrs['protected'])) | |
| 192 | + if (isset($aClassAttrs['protected'])) | |
| 193 | 193 |              { | 
| 194 | 194 | return [true, [], []]; // The entire class is not to be exported. | 
| 195 | 195 | } | 
| 196 | 196 | |
| 197 | 197 | // Merge attributes and class annotations | 
| 198 | - foreach($aPropAttrs as $sName => $xValue) | |
| 198 | + foreach ($aPropAttrs as $sName => $xValue) | |
| 199 | 199 |              { | 
| 200 | 200 | $aClassAttrs[$sName] = array_merge($aClassAttrs[$sName] ?? [], $xValue); | 
| 201 | 201 | } | 
| @@ -205,21 +205,21 @@ discard block | ||
| 205 | 205 | |
| 206 | 206 | $aAttributes = count($aClassAttrs) > 0 ? ['*' => $aClassAttrs] : []; | 
| 207 | 207 | $aProtected = []; | 
| 208 | - foreach($aMethods as $sMethod) | |
| 208 | + foreach ($aMethods as $sMethod) | |
| 209 | 209 |              { | 
| 210 | 210 | $aMethodAttrs = $this->filterAnnotations($this->xManager->getMethodAnnotations($sClass, $sMethod)); | 
| 211 | - if(isset($aMethodAttrs['protected'])) | |
| 211 | + if (isset($aMethodAttrs['protected'])) | |
| 212 | 212 |                  { | 
| 213 | 213 | $aProtected[] = $sMethod; // The method is not to be exported. | 
| 214 | 214 | } | 
| 215 | - elseif(count($aMethodAttrs) > 0) | |
| 215 | + elseif (count($aMethodAttrs) > 0) | |
| 216 | 216 |                  { | 
| 217 | 217 | $aAttributes[$sMethod] = $aMethodAttrs; | 
| 218 | 218 | } | 
| 219 | 219 | } | 
| 220 | 220 | return [false, $aAttributes, $aProtected]; | 
| 221 | 221 | } | 
| 222 | - catch(AnnotationException $e) | |
| 222 | + catch (AnnotationException $e) | |
| 223 | 223 |          { | 
| 224 | 224 | throw new SetupException($e->getMessage()); | 
| 225 | 225 | } | 
| @@ -22,13 +22,13 @@ discard block | ||
| 22 | 22 | */ | 
| 23 | 23 | function register(Container $di, bool $bForce = false) | 
| 24 | 24 |  { | 
| 25 | - if(!$bForce && $di->h(AnnotationReader::class)) | |
| 25 | + if (!$bForce && $di->h(AnnotationReader::class)) | |
| 26 | 26 |      { | 
| 27 | 27 | return; | 
| 28 | 28 | } | 
| 29 | 29 | |
| 30 | 30 | $sCacheDirKey = 'jaxon_annotations_cache_dir'; | 
| 31 | - if(!$di->h($sCacheDirKey)) | |
| 31 | + if (!$di->h($sCacheDirKey)) | |
| 32 | 32 |      { | 
| 33 | 33 | $di->val($sCacheDirKey, sys_get_temp_dir()); | 
| 34 | 34 | } | 
| @@ -49,7 +49,7 @@ discard block | ||
| 49 | 49 |  { | 
| 50 | 50 | $di = jaxon()->di(); | 
| 51 | 51 | $sEventListenerKey = AnnotationReader::class . '\\ConfigListener'; | 
| 52 | - if($di->h($sEventListenerKey)) | |
| 52 | + if ($di->h($sEventListenerKey)) | |
| 53 | 53 |      { | 
| 54 | 54 | return; | 
| 55 | 55 | } | 
| @@ -62,7 +62,7 @@ discard block | ||
| 62 | 62 | public function onChange(Config $xConfig, string $sName) | 
| 63 | 63 |              { | 
| 64 | 64 | $sConfigKey = 'core.annotations.enabled'; | 
| 65 | - if(($sName === $sConfigKey || $sName === '') && $xConfig->getOption($sConfigKey)) | |
| 65 | + if (($sName === $sConfigKey || $sName === '') && $xConfig->getOption($sConfigKey)) | |
| 66 | 66 |                  { | 
| 67 | 67 | register(jaxon()->di()); | 
| 68 | 68 | } |