Conditions | 22 |
Paths | 3072 |
Total Lines | 88 |
Code Lines | 57 |
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 |
||
46 | public function make(string $date): AbstractCalendarDate |
||
47 | { |
||
48 | // Valid calendar escape specified? - use it |
||
49 | if (preg_match('/^(@#D(?:GREGORIAN|JULIAN|HEBREW|HIJRI|JALALI|FRENCH R|ROMAN)+@) ?(.*)/', $date, $match)) { |
||
50 | $cal = $match[1]; |
||
51 | $date = $match[2]; |
||
52 | } else { |
||
53 | $cal = ''; |
||
54 | } |
||
55 | // A date with a month: DM, M, MY or DMY |
||
56 | if (preg_match('/^(\d?\d?) ?(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|TSH|CSH|KSL|TVT|SHV|ADR|ADS|NSN|IYR|SVN|TMZ|AAV|ELL|VEND|BRUM|FRIM|NIVO|PLUV|VENT|GERM|FLOR|PRAI|MESS|THER|FRUC|COMP|MUHAR|SAFAR|RABI[AT]|JUMA[AT]|RAJAB|SHAAB|RAMAD|SHAWW|DHUAQ|DHUAH|FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN) ?((?:\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d)?)$/', $date, $match)) { |
||
57 | $d = $match[1]; |
||
58 | $m = $match[2]; |
||
59 | $y = $match[3]; |
||
60 | } elseif (preg_match('/^(\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d)$/', $date, $match)) { |
||
61 | // A date with just a year |
||
62 | $d = ''; |
||
63 | $m = ''; |
||
64 | $y = $match[1]; |
||
65 | } else { |
||
66 | // An invalid date - do the best we can. |
||
67 | $d = ''; |
||
68 | $m = ''; |
||
69 | $y = ''; |
||
70 | // Look for a 3/4 digit year anywhere in the date |
||
71 | if (preg_match('/(\d{3,4})/', $date, $match)) { |
||
72 | $y = $match[1]; |
||
73 | } |
||
74 | // Look for a month anywhere in the date |
||
75 | if (preg_match('/(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|TSH|CSH|KSL|TVT|SHV|ADR|ADS|NSN|IYR|SVN|TMZ|AAV|ELL|VEND|BRUM|FRIM|NIVO|PLUV|VENT|GERM|FLOR|PRAI|MESS|THER|FRUC|COMP|MUHAR|SAFAR|RABI[AT]|JUMA[AT]|RAJAB|SHAAB|RAMAD|SHAWW|DHUAQ|DHUAH|FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN)/', $date, $match)) { |
||
76 | $m = $match[1]; |
||
77 | // Look for a day number anywhere in the date |
||
78 | if (preg_match('/\b(\d\d?)\b/', $date, $match)) { |
||
79 | $d = $match[1]; |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | |||
84 | // Unambiguous dates - override calendar escape |
||
85 | if (preg_match('/^(TSH|CSH|KSL|TVT|SHV|ADR|ADS|NSN|IYR|SVN|TMZ|AAV|ELL)$/', $m)) { |
||
86 | $cal = JewishDate::ESCAPE; |
||
87 | } elseif (preg_match('/^(VEND|BRUM|FRIM|NIVO|PLUV|VENT|GERM|FLOR|PRAI|MESS|THER|FRUC|COMP)$/', $m)) { |
||
88 | $cal = FrenchDate::ESCAPE; |
||
89 | } elseif (preg_match('/^(MUHAR|SAFAR|RABI[AT]|JUMA[AT]|RAJAB|SHAAB|RAMAD|SHAWW|DHUAQ|DHUAH)$/', $m)) { |
||
90 | $cal = HijriDate::ESCAPE; // This is a WT extension |
||
91 | } elseif (preg_match('/^(FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN)$/', $m)) { |
||
92 | $cal = JalaliDate::ESCAPE; // This is a WT extension |
||
93 | } elseif (preg_match('/^\d{1,4}( B\.C\.)|\d\d\d\d\/\d\d$/', $y)) { |
||
94 | $cal = JulianDate::ESCAPE; |
||
95 | } |
||
96 | |||
97 | // Ambiguous dates - don't override calendar escape |
||
98 | if ($cal === '') { |
||
99 | if (preg_match('/^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)$/', $m)) { |
||
100 | $cal = GregorianDate::ESCAPE; |
||
101 | } elseif (preg_match('/^[345]\d\d\d$/', $y)) { |
||
102 | // Year 3000-5999 |
||
103 | $cal = JewishDate::ESCAPE; |
||
104 | } else { |
||
105 | $cal = GregorianDate::ESCAPE; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | // Now construct an object of the correct type |
||
110 | switch ($cal) { |
||
111 | case GregorianDate::ESCAPE: |
||
112 | return new GregorianDate([$y, $m, $d]); |
||
113 | |||
114 | case JulianDate::ESCAPE: |
||
115 | return new JulianDate([$y, $m, $d]); |
||
116 | |||
117 | case JewishDate::ESCAPE: |
||
118 | return new JewishDate([$y, $m, $d]); |
||
119 | |||
120 | case HijriDate::ESCAPE: |
||
121 | return new HijriDate([$y, $m, $d]); |
||
122 | |||
123 | case FrenchDate::ESCAPE: |
||
124 | return new FrenchDate([$y, $m, $d]); |
||
125 | |||
126 | case JalaliDate::ESCAPE: |
||
127 | return new JalaliDate([$y, $m, $d]); |
||
128 | |||
129 | case RomanDate::ESCAPE: |
||
130 | return new RomanDate([$y, $m, $d]); |
||
131 | |||
132 | default: |
||
133 | throw new DomainException('Invalid calendar'); |
||
134 | } |
||
160 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths