| Conditions | 2 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 21 |
| 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 |
||
| 57 | private function prototype($sourceCurrencyCode = null, $targetCurrencyCode = null, float $ratio = null, \DateTimeInterface $day = null): ExchangeRateInterface |
||
| 58 | { |
||
| 59 | if (null === $this->prototype) { |
||
| 60 | $this->prototype = new class($sourceCurrencyCode, $targetCurrencyCode, $ratio) implements ExchangeRateInterface |
||
| 61 | { |
||
| 62 | |||
| 63 | public $id, $sourceCurrencyCode, $targetCurrencyCode, $ratio, $day; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * constructor. |
||
| 67 | * @param CurrencyInterface $sourceCurrency |
||
|
|
|||
| 68 | * @param CurrencyInterface $targetCurrency |
||
| 69 | * @param float $ratio |
||
| 70 | * @param \DateTimeInterface|null $day |
||
| 71 | */ |
||
| 72 | public function __construct($sourceCurrencyCode = null, $targetCurrencyCode = null, float $ratio = null, \DateTimeInterface $day = null) |
||
| 73 | { |
||
| 74 | if (null !== $sourceCurrencyCode && null !== $targetCurrencyCode) { |
||
| 75 | $this->id = sprintf('%s%s', $sourceCurrencyCode, $targetCurrencyCode); |
||
| 76 | } |
||
| 77 | $this->sourceCurrencyCode = $sourceCurrencyCode; |
||
| 78 | $this->targetCurrencyCode = $targetCurrencyCode; |
||
| 79 | $this->ratio = $ratio; |
||
| 80 | $this->day = $day; |
||
| 81 | } |
||
| 82 | |||
| 83 | public function getRatio(): float |
||
| 84 | { |
||
| 85 | return $this->ratio; |
||
| 86 | } |
||
| 87 | |||
| 88 | public function getSourceCurrency(): CurrencyInterface |
||
| 89 | { |
||
| 90 | return new Currency($this->sourceCurrencyCode); |
||
| 91 | } |
||
| 92 | |||
| 93 | public function getTargetCurrency(): CurrencyInterface |
||
| 94 | { |
||
| 95 | return new Currency($this->targetCurrencyCode); |
||
| 96 | } |
||
| 97 | |||
| 98 | public function new($sourceCurrencyCode = null, $targetCurrencyCode = null, float $ratio = null, \DateTimeInterface $day = null): self |
||
| 99 | { |
||
| 100 | return new self($sourceCurrencyCode, $targetCurrencyCode, $ratio, $day); |
||
| 101 | } |
||
| 102 | |||
| 103 | }; |
||
| 104 | return $this->prototype; |
||
| 105 | } |
||
| 106 | return $this->prototype->new($sourceCurrencyCode, $targetCurrencyCode, $ratio, $day); |
||
| 107 | } |
||
| 108 | } |
||
| 109 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.