Conditions | 1 |
Paths | 1 |
Total Lines | 118 |
Code Lines | 84 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
37 | public function providerExtractFromJson(): Generator |
||
38 | { |
||
39 | yield 'One add' => [ |
||
40 | 'allItems' => [ |
||
41 | [ |
||
42 | 'type' => 'ad', |
||
43 | 'title' => 'This is an add', |
||
44 | 'pubtime' => self::EXAMPLE_UNIX_PUBTIME, |
||
45 | 'url' => 'url.com', |
||
46 | 'summary' => 'A summary', |
||
47 | ], |
||
48 | ], |
||
49 | 'expected' => [], |
||
50 | ]; |
||
51 | |||
52 | yield 'One video' => [ |
||
53 | 'allItems' => [ |
||
54 | [ |
||
55 | 'type' => 'video', |
||
56 | 'title' => 'This is a video', |
||
57 | 'pubtime' => self::EXAMPLE_UNIX_PUBTIME, |
||
58 | 'url' => 'url.com', |
||
59 | 'summary' => 'A summary', |
||
60 | ], |
||
61 | ], |
||
62 | 'expected' => [], |
||
63 | ]; |
||
64 | |||
65 | yield 'One article' => [ |
||
66 | 'allItems' => [ |
||
67 | [ |
||
68 | 'type' => 'article', |
||
69 | 'title' => 'The title', |
||
70 | 'pubtime' => self::EXAMPLE_UNIX_PUBTIME, |
||
71 | 'url' => 'url.com', |
||
72 | 'summary' => 'A summary', |
||
73 | 'publisher' => null, |
||
74 | 'images' => [], |
||
75 | ], |
||
76 | ], |
||
77 | 'expected' => [ |
||
78 | [ |
||
79 | 'title' => 'The title', |
||
80 | 'datetime' => self::EXAMPLE_FORMATTED_DATETIME, |
||
81 | 'url' => 'url.com', |
||
82 | 'summary' => 'A summary', |
||
83 | 'timezone' => self::EXAMPLE_TIMEZONE, |
||
84 | 'source' => 'FinanceYahoo', |
||
85 | 'publisher' => null, |
||
86 | 'images' => [], |
||
87 | ], |
||
88 | ], |
||
89 | ]; |
||
90 | |||
91 | yield 'A mix with add, video and articles' => [ |
||
92 | 'allItems' => [ |
||
93 | [ |
||
94 | 'type' => '-', |
||
95 | 'title' => 'Unknown type title', |
||
96 | 'pubtime' => self::EXAMPLE_UNIX_PUBTIME, |
||
97 | 'url' => 'url.~0~.com', |
||
98 | 'summary' => 'summary', |
||
99 | ], |
||
100 | [ |
||
101 | 'type' => 'ad', |
||
102 | 'title' => 'This is an Add!', |
||
103 | 'pubtime' => self::EXAMPLE_UNIX_PUBTIME, |
||
104 | 'url' => 'url.~1~.com', |
||
105 | 'summary' => 'summary', |
||
106 | ], |
||
107 | [ |
||
108 | 'type' => 'article', |
||
109 | 'title' => 'The first title', |
||
110 | 'pubtime' => self::EXAMPLE_UNIX_PUBTIME, |
||
111 | 'url' => 'url.1.com', |
||
112 | 'summary' => 'First summary', |
||
113 | 'source' => 'FinanceYahoo', |
||
114 | 'publisher' => null, |
||
115 | 'images' => [], |
||
116 | ], |
||
117 | [ |
||
118 | 'type' => 'video', |
||
119 | 'title' => 'This is another Add!', |
||
120 | 'pubtime' => self::EXAMPLE_UNIX_PUBTIME, |
||
121 | 'url' => 'url.~2~.com', |
||
122 | 'summary' => 'summary', |
||
123 | ], |
||
124 | [ |
||
125 | 'type' => 'article', |
||
126 | 'title' => 'The second title', |
||
127 | 'pubtime' => self::EXAMPLE_UNIX_PUBTIME, |
||
128 | 'url' => 'url.2.com', |
||
129 | 'summary' => 'Second summary', |
||
130 | 'source' => 'FinanceYahoo', |
||
131 | 'publisher' => null, |
||
132 | 'images' => [], |
||
133 | ], |
||
134 | ], |
||
135 | 'expected' => [ |
||
136 | [ |
||
137 | 'title' => 'The first title', |
||
138 | 'datetime' => self::EXAMPLE_FORMATTED_DATETIME, |
||
139 | 'url' => 'url.1.com', |
||
140 | 'summary' => 'First summary', |
||
141 | 'timezone' => self::EXAMPLE_TIMEZONE, |
||
142 | 'source' => 'FinanceYahoo', |
||
143 | 'publisher' => null, |
||
144 | 'images' => [], |
||
145 | ], |
||
146 | [ |
||
147 | 'title' => 'The second title', |
||
148 | 'datetime' => self::EXAMPLE_FORMATTED_DATETIME, |
||
149 | 'url' => 'url.2.com', |
||
150 | 'summary' => 'Second summary', |
||
151 | 'timezone' => self::EXAMPLE_TIMEZONE, |
||
152 | 'source' => 'FinanceYahoo', |
||
153 | 'publisher' => null, |
||
154 | 'images' => [], |
||
155 | ], |
||
183 |