Conditions | 8 |
Paths | 8 |
Total Lines | 54 |
Code Lines | 26 |
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 |
||
66 | protected function getOffsetFor(DateRepresentationInterface $input, $timestamp) |
||
67 | { |
||
68 | $input = $this->extractAbbreviation($input); |
||
69 | $offset = $input->getOffset(); |
||
70 | |||
71 | if (null !== $offset->getValue()) { |
||
72 | return $input; |
||
73 | } |
||
74 | |||
75 | // Looking for timezone offset matching the incomplete timestamp. |
||
76 | // The LMT transition is skipped to mirror the behaviour of |
||
77 | // DateTimeZone->getOffset() |
||
|
|||
78 | $previous = null; |
||
79 | |||
80 | $offsets = $input->getTimezone()->getTransitions( |
||
81 | $timestamp - $this->dayLengthInSeconds, |
||
82 | // Usually, $timestamp + $this->dayLengthInSeconds should be enougth, |
||
83 | // but for dates before 1900-01-01 timezones fallback to LMT that |
||
84 | // we are trying to skip. |
||
85 | max(0, $timestamp + $this->dayLengthInSeconds) |
||
86 | ); |
||
87 | |||
88 | // DateTimeZone can return a false $offsets value for unsupported ranges. |
||
89 | if (false === $offsets) { |
||
90 | return $input->withOffset( |
||
91 | $offset |
||
92 | ->withValue( |
||
93 | $input->getTimezone()->getOffset( |
||
94 | new DateTimeImmutable() |
||
95 | ) |
||
96 | ) |
||
97 | ) |
||
98 | ; |
||
99 | } |
||
100 | |||
101 | foreach ($offsets as $info) { |
||
102 | if ( |
||
103 | (!$previous || $previous['abbr'] !== 'LMT') |
||
104 | && $timestamp - $info['offset'] < $info['ts'] |
||
105 | ) { |
||
106 | break; |
||
107 | } |
||
108 | |||
109 | $previous = $info; |
||
110 | } |
||
111 | |||
112 | if ($previous === null) { |
||
113 | return $input; |
||
114 | } |
||
115 | |||
116 | return $input->withOffset(new TimeOffsetValue( |
||
117 | $previous['offset'], |
||
118 | $previous['isdst'], |
||
119 | $previous['abbr'] |
||
120 | )); |
||
180 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.