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