| Conditions | 7 |
| Paths | 5 |
| Total Lines | 52 |
| 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 |
||
| 44 | public function __construct($templatingOrDeprecatedName, object $templatingOrAuditReader, ?AuditReader $auditReader = null) |
||
| 45 | { |
||
| 46 | if ($templatingOrAuditReader instanceof EngineInterface) { |
||
| 47 | @trigger_error(sprintf( |
||
|
|
|||
| 48 | 'Passing %s as argument 2 to %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.21' |
||
| 49 | .' and will throw a \TypeError in version 4.0. You must pass an instance of %s instead.', |
||
| 50 | EngineInterface::class, |
||
| 51 | __METHOD__, |
||
| 52 | AuditReader::class |
||
| 53 | ), E_USER_DEPRECATED); |
||
| 54 | |||
| 55 | if (null === $auditReader) { |
||
| 56 | throw new \TypeError(sprintf( |
||
| 57 | 'Passing null as argument 3 to %s() is not allowed when %s is passed as argument 2.' |
||
| 58 | .' You must pass an instance of %s instead.', |
||
| 59 | __METHOD__, |
||
| 60 | EngineInterface::class, |
||
| 61 | AuditReader::class |
||
| 62 | )); |
||
| 63 | } |
||
| 64 | |||
| 65 | parent::__construct($templatingOrDeprecatedName, $templatingOrAuditReader); |
||
| 66 | |||
| 67 | $this->auditReader = $auditReader; |
||
| 68 | } elseif ($templatingOrAuditReader instanceof AuditReader) { |
||
| 69 | if (!$templatingOrDeprecatedName instanceof Environment |
||
| 70 | && !$templatingOrDeprecatedName instanceof EngineInterface |
||
| 71 | ) { |
||
| 72 | throw new \TypeError(sprintf( |
||
| 73 | 'Argument 1 passed to %s() must be either an instance of %s or preferably %s, %s given.', |
||
| 74 | __METHOD__, |
||
| 75 | EngineInterface::class, |
||
| 76 | Environment::class, |
||
| 77 | \is_object($templatingOrDeprecatedName) |
||
| 78 | ? 'instance of '.\get_class($templatingOrDeprecatedName) |
||
| 79 | : \gettype($templatingOrDeprecatedName) |
||
| 80 | )); |
||
| 81 | } |
||
| 82 | |||
| 83 | parent::__construct($templatingOrDeprecatedName); |
||
| 84 | |||
| 85 | $this->auditReader = $templatingOrAuditReader; |
||
| 86 | } else { |
||
| 87 | throw new \TypeError(sprintf( |
||
| 88 | 'Argument 2 passed to %s() must be either an instance of %s or preferably %s, instance of %s given.', |
||
| 89 | __METHOD__, |
||
| 90 | EngineInterface::class, |
||
| 91 | AuditReader::class, |
||
| 92 | \get_class($templatingOrAuditReader) |
||
| 93 | )); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 132 |
If you suppress an error, we recommend checking for the error condition explicitly: