| Conditions | 12 |
| Paths | 384 |
| Total Lines | 40 |
| Code Lines | 25 |
| 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 |
||
| 84 | private function convertContext(Context $context = null, $direction) |
||
| 85 | { |
||
| 86 | if (self::SERIALIZATION === $direction) { |
||
| 87 | $jmsContext = $this->serializationContextFactory |
||
| 88 | ? $this->serializationContextFactory->createSerializationContext() |
||
| 89 | : SerializationContext::create(); |
||
| 90 | } else { |
||
| 91 | $jmsContext = $this->deserializationContextFactory |
||
| 92 | ? $this->deserializationContextFactory->createDeserializationContext() |
||
| 93 | : DeserializationContext::create(); |
||
| 94 | $maxDepth = $context->getMaxDepth(false); |
||
| 95 | if (null !== $maxDepth) { |
||
| 96 | for ($i = 0; $i < $maxDepth; ++$i) { |
||
| 97 | $jmsContext->increaseDepth(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | foreach ($context->getAttributes() as $key => $value) { |
||
| 103 | $jmsContext->attributes->set($key, $value); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (null !== $context->getVersion()) { |
||
| 107 | $jmsContext->setVersion($context->getVersion()); |
||
| 108 | } |
||
| 109 | if (null !== $context->getGroups()) { |
||
| 110 | $jmsContext->setGroups($context->getGroups()); |
||
| 111 | } |
||
| 112 | if (null !== $context->isMaxDepthEnabled()) { |
||
| 113 | $jmsContext->enableMaxDepthChecks(); |
||
| 114 | } |
||
| 115 | if (null !== $context->getSerializeNull()) { |
||
| 116 | $jmsContext->setSerializeNull($context->getSerializeNull()); |
||
| 117 | } |
||
| 118 | |||
| 119 | foreach ($context->getExclusionStrategies() as $strategy) { |
||
| 120 | $jmsContext->addExclusionStrategy($strategy); |
||
| 121 | } |
||
| 122 | |||
| 123 | return $jmsContext; |
||
| 124 | } |
||
| 159 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: