| Conditions | 22 |
| Paths | 209 |
| Total Lines | 62 |
| 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 |
||
| 94 | private function getRenderer($object, string $context = null): ?ChainableRendererInterface |
||
| 95 | { |
||
| 96 | $cacheKey = "chainRendererByClass_".md5($this->uniqueName."/".$this->templateRendererInstanceName."/".get_class($object)."/".$context); |
||
| 97 | |||
| 98 | $cachedInstanceName = $this->cacheService->get($cacheKey); |
||
| 99 | if ($cachedInstanceName !== null) { |
||
| 100 | return $this->container->get($cachedInstanceName); |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->initRenderersList(); |
||
| 104 | |||
| 105 | $isCachable = true; |
||
| 106 | $foundRenderer = null; |
||
| 107 | $source = null; |
||
|
|
|||
| 108 | $foundInstanceName = null; |
||
| 109 | |||
| 110 | do { |
||
| 111 | foreach ($this->customRenderers as $instanceName => $renderer) { |
||
| 112 | $result = $renderer->canRender($object, $context); |
||
| 113 | if ($result === ChainableRendererInterface::CAN_RENDER_OBJECT || $result === ChainableRendererInterface::CANNOT_RENDER_OBJECT) { |
||
| 114 | $isCachable = false; |
||
| 115 | } |
||
| 116 | if ($result === ChainableRendererInterface::CAN_RENDER_OBJECT || $result === ChainableRendererInterface::CAN_RENDER_CLASS) { |
||
| 117 | $foundRenderer = $renderer; |
||
| 118 | $foundInstanceName = $instanceName; |
||
| 119 | break 2; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | if ($this->templateRendererInstanceName && !$this->templateRenderer) { |
||
| 124 | $this->templateRenderer = $this->container->get($this->templateRendererInstanceName); |
||
| 125 | } |
||
| 126 | if ($this->templateRenderer) { |
||
| 127 | $result = $this->templateRenderer->canRender($object, $context); |
||
| 128 | if ($result === ChainableRendererInterface::CAN_RENDER_OBJECT || $result === ChainableRendererInterface::CANNOT_RENDER_OBJECT) { |
||
| 129 | $isCachable = false; |
||
| 130 | } |
||
| 131 | if ($result === ChainableRendererInterface::CAN_RENDER_OBJECT || $result === ChainableRendererInterface::CAN_RENDER_CLASS) { |
||
| 132 | $foundRenderer = $this->templateRenderer; |
||
| 133 | break; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | foreach ($this->packageRenderers as $instanceName => $renderer) { |
||
| 138 | $result = $renderer->canRender($object, $context); |
||
| 139 | if ($result === ChainableRendererInterface::CAN_RENDER_OBJECT || $result === ChainableRendererInterface::CANNOT_RENDER_OBJECT) { |
||
| 140 | $isCachable = false; |
||
| 141 | } |
||
| 142 | if ($result === ChainableRendererInterface::CAN_RENDER_OBJECT || $result === ChainableRendererInterface::CAN_RENDER_CLASS) { |
||
| 143 | $foundRenderer = $renderer; |
||
| 144 | $foundInstanceName = $instanceName; |
||
| 145 | break 2; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } while (false); |
||
| 149 | |||
| 150 | if ($isCachable && $foundRenderer) { |
||
| 151 | $this->cacheService->set($cacheKey, $foundInstanceName); |
||
| 152 | } |
||
| 153 | |||
| 154 | return $foundRenderer; |
||
| 155 | } |
||
| 156 | |||
| 234 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.