Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Tests | 53 |
CRAP Score | 1 |
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 |
||
18 | 45 | public function getFilters() |
|
19 | { |
||
20 | return [ |
||
21 | 45 | new Twig_SimpleFilter( |
|
22 | 45 | 'ordinalize', |
|
23 | 30 | function ($number) { |
|
24 | 3 | return NumberHumanizer::ordinalize( |
|
25 | 2 | $number, |
|
26 | 3 | $this->translator->getLocale() |
|
27 | 1 | ); |
|
28 | 30 | } |
|
29 | 15 | ), |
|
30 | 30 | new Twig_SimpleFilter('ordinal', function ($number) { |
|
31 | 3 | return NumberHumanizer::ordinal( |
|
32 | 2 | $number, |
|
33 | 3 | $this->translator->getLocale() |
|
34 | 1 | ); |
|
35 | 45 | }), |
|
36 | 45 | new Twig_SimpleFilter( |
|
37 | 45 | 'binary_suffix', |
|
38 | 30 | function ($number) { |
|
39 | 3 | return NumberHumanizer::binarySuffix( |
|
40 | 2 | $number, |
|
41 | 3 | $this->translator->getLocale() |
|
42 | 1 | ); |
|
43 | 30 | } |
|
44 | 15 | ), |
|
45 | 45 | new Twig_SimpleFilter( |
|
46 | 45 | 'precise_binary_suffix', |
|
47 | 30 | function ($number, $precision) { |
|
48 | 3 | return NumberHumanizer::preciseBinarySuffix( |
|
49 | 2 | $number, |
|
50 | 2 | $precision, |
|
51 | 3 | $this->translator->getLocale() |
|
52 | 1 | ); |
|
53 | 30 | } |
|
54 | 15 | ), |
|
55 | 45 | new Twig_SimpleFilter( |
|
56 | 45 | 'metric_suffix', |
|
57 | 31 | function ($number) { |
|
58 | 3 | return NumberHumanizer::metricSuffix( |
|
59 | 2 | $number, |
|
60 | 3 | $this->translator->getLocale() |
|
61 | 1 | ); |
|
62 | 30 | } |
|
63 | 15 | ), |
|
64 | 45 | new Twig_SimpleFilter( |
|
65 | 45 | 'to_roman', |
|
66 | 45 | [NumberHumanizer::class, 'toRoman'] |
|
67 | 15 | ), |
|
68 | 45 | new Twig_SimpleFilter( |
|
69 | 45 | 'from_roman', |
|
70 | 45 | [NumberHumanizer::class, 'fromRoman'] |
|
71 | 15 | ), |
|
72 | 15 | ]; |
|
73 | } |
||
74 | |||
80 |