| Conditions | 13 |
| Paths | 35 |
| Total Lines | 51 |
| Code Lines | 29 |
| 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 |
||
| 32 | public function compare( DataValue $value, DataValue $comparativeValue ) { |
||
| 33 | if ( !$this->canCompare( $value, $comparativeValue ) ) { |
||
| 34 | throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var TimeValue $value |
||
| 39 | * @var TimeValue $comparativeValue |
||
| 40 | */ |
||
| 41 | |||
| 42 | $result = ComparisonResult::STATUS_MISMATCH; |
||
| 43 | |||
| 44 | if ( !preg_match( '/^([-+]?)(\d*)((\d{4}\b).*)/', $value->getTime(), $localMatches ) |
||
| 45 | || !preg_match( '/^([-+]?)(\d*)((\d{4}\b).*)/', $comparativeValue->getTime(), $externalMatches ) |
||
| 46 | ) { |
||
| 47 | return ComparisonResult::STATUS_MISMATCH; |
||
| 48 | } |
||
| 49 | list( , $localSign, $localYearHigh, $localMwTime, $localYearLow ) = $localMatches; |
||
| 50 | list( , $externalSign, $externalYearHigh, $externalMwTime, $externalYearLow ) = $externalMatches; |
||
| 51 | if ( $localSign !== $externalSign && ( $localYearHigh . $localYearLow !== '0000' |
||
| 52 | || $externalYearHigh . $externalYearLow !== '0000' ) |
||
| 53 | ) { |
||
| 54 | return ComparisonResult::STATUS_MISMATCH; |
||
| 55 | } |
||
| 56 | |||
| 57 | $localYearHigh = $localYearHigh === '' ? 0 : (int)$localYearHigh; |
||
| 58 | $externalYearHigh = $externalYearHigh === '' ? 0 : (int)$externalYearHigh; |
||
| 59 | |||
| 60 | try { |
||
| 61 | $localTimestamp = new MWTimestamp( $localMwTime ); |
||
| 62 | $externalTimestamp = new MWTimestamp( $externalMwTime ); |
||
| 63 | $diff = $localTimestamp->diff( $externalTimestamp ); |
||
| 64 | $diff->y += abs( $localYearHigh - $externalYearHigh ) * 10000; |
||
| 65 | |||
| 66 | if ( $value->getPrecision() === $comparativeValue->getPrecision() |
||
| 67 | && $this->resultOfDiffWithPrecision( $diff, $value->getPrecision() ) |
||
| 68 | ) { |
||
| 69 | $result = ComparisonResult::STATUS_MATCH; |
||
| 70 | } elseif ( |
||
| 71 | $this->resultOfDiffWithPrecision( |
||
| 72 | $diff, |
||
| 73 | min( $value->getPrecision(), $comparativeValue->getPrecision() ) |
||
| 74 | ) |
||
| 75 | ) { |
||
| 76 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
||
| 77 | } |
||
| 78 | } catch ( TimestampException $ex ) { |
||
| 79 | } |
||
| 80 | |||
| 81 | return $result; |
||
| 82 | } |
||
| 83 | |||
| 160 |