| Conditions | 21 |
| Paths | 544 |
| Total Lines | 71 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 52 | public function onMethodInject(IAnnotatable $instance, \ReflectionMethod $method, Container $container) |
||
| 53 | { |
||
| 54 | $filename = array_key_exists('value', $this->injectAnnotation) ? $this->injectAnnotation['value'] : null; |
||
| 55 | $engine = array_key_exists('engine', $this->injectAnnotation) ? $this->injectAnnotation['engine'] : "basic"; |
||
| 56 | $debug = array_key_exists('debug', $this->injectAnnotation) ? $this->injectAnnotation['debug'] : false; |
||
| 57 | $cacheTime = array_key_exists('cacheTime', $this->injectAnnotation) ? $this->injectAnnotation['cacheTime'] : null; |
||
| 58 | $logger = $container->logger; |
||
|
|
|||
| 59 | |||
| 60 | if (PHP_OS === "WIN32" || PHP_OS === "WINNT") { |
||
| 61 | if (preg_match("/^.*[. ]|.*[\p{Cntrl}\/:*?\"<>|].*|(?i:CON|PRN|AUX|CLOCK\$|NUL|COM[1-9]|LPT[1-9])(?:[.].+)?$/", $filename)) { |
||
| 62 | throw new AnnotationException("Invalid string contains in @Template('$filename')"); |
||
| 63 | } |
||
| 64 | } else { |
||
| 65 | if (preg_match("/:|\.\.\/|\.\.\\\\/", $filename)) { |
||
| 66 | throw new AnnotationException("Invalid string contains in @Template('$filename')"); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($filename === null) { |
||
| 71 | $errorMsg = "Invalid argument of @Template('$filename'). There is no specification of the base template."; |
||
| 72 | throw new AnnotationException($errorMsg); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($engine === "twig") { |
||
| 76 | if (!is_bool($debug)) { |
||
| 77 | if ($debug !== null) { |
||
| 78 | $errorMsg = "Invalid argument of @Template('$filename'). 'debug' attribute bool only be specified."; |
||
| 79 | throw new AnnotationException($errorMsg); |
||
| 80 | } |
||
| 81 | $debug = false; |
||
| 82 | } |
||
| 83 | $this->readAnnotation['filename'] = $filename; |
||
| 84 | $this->readAnnotation['engine'] = $container->engine['twig']; |
||
| 85 | $this->readAnnotation['debug'] = $debug; |
||
| 86 | |||
| 87 | if ($cacheTime !== null) { |
||
| 88 | $logger->warn("'cacheTime' attribute is not used in Twig template."); |
||
| 89 | } |
||
| 90 | } elseif ($engine === "basic") { |
||
| 91 | if ($cacheTime !== null) { |
||
| 92 | // 複数指定は不可 |
||
| 93 | if (is_array($cacheTime)) { |
||
| 94 | $errorMsg = "Invalid argument of @Template attribute 'cacheTime' should not be array."; |
||
| 95 | throw new AnnotationException($errorMsg); |
||
| 96 | } |
||
| 97 | // 数値以外は不可 |
||
| 98 | if (!preg_match("/^[1-9]{1}[0-9]{0,}$/", $cacheTime)) { |
||
| 99 | $errorMsg = "Invalid argument of @Template attribute 'cacheTime' should not be integer."; |
||
| 100 | throw new AnnotationException($errorMsg); |
||
| 101 | } |
||
| 102 | |||
| 103 | $cacheTime = intval($cacheTime); |
||
| 104 | if ($cacheTime <= 0) { |
||
| 105 | $errorMsg = "Expire value is out of integer range: @Template(cacheTime=" . strval($cacheTime) . ")"; |
||
| 106 | throw new AnnotationException($errorMsg); |
||
| 107 | } elseif ($cacheTime >= PHP_INT_MAX) { |
||
| 108 | $logger->warn("Expire value converted the maximum of PHP Integer."); |
||
| 109 | } |
||
| 110 | |||
| 111 | $this->readAnnotation['cacheTime'] = $cacheTime; |
||
| 112 | } |
||
| 113 | |||
| 114 | $this->readAnnotation['filename'] = $filename; |
||
| 115 | $this->readAnnotation['engine'] = $container->engine['basic']; |
||
| 116 | |||
| 117 | if ($debug !== null) { |
||
| 118 | $logger->warn("'debug' attribute is not used in Basic template."); |
||
| 119 | } |
||
| 120 | } else { |
||
| 121 | $errorMsg = "Invalid 'engine' attribute of @Template('$filename')."; |
||
| 122 | throw new AnnotationException($errorMsg); |
||
| 123 | } |
||
| 126 |