Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 42 |
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 declare(strict_types=1); |
||
23 | public static function create(array $data): \One\Model\Article |
||
24 | { |
||
25 | $data = self::validateArray($data); |
||
26 | $title = self::validateString( |
||
27 | (string) self::checkData($data, 'title', '') |
||
28 | ); |
||
29 | $body = self::validateString( |
||
30 | (string) self::checkData($data, 'body', '') |
||
31 | ); |
||
32 | $source = self::validateUrl( |
||
33 | (string) self::checkData($data, 'source', '') |
||
34 | ); |
||
35 | $uniqueId = self::validateString( |
||
36 | (string) self::checkData($data, 'unique_id', '') |
||
37 | ); |
||
38 | $typeId = self::validateInteger( |
||
39 | (int) self::checkData($data, 'type_id', '') |
||
40 | ); |
||
41 | $categoryId = self::validateInteger( |
||
42 | (int) self::checkData($data, 'category_id', '') |
||
43 | ); |
||
44 | $reporter = self::validateString( |
||
45 | (string) self::checkData($data, 'reporter', '') |
||
46 | ); |
||
47 | $lead = self::validateString( |
||
48 | (string) self::checkData($data, 'lead', '') |
||
49 | ); |
||
50 | $tags = self::validateString( |
||
51 | (string) self::checkData($data, 'tags', '') |
||
52 | ); |
||
53 | $publishedAt = self::validateString( |
||
54 | (string) self::checkData($data, 'published_at', '') |
||
55 | ); |
||
56 | $headline = (bool) self::checkData($data, 'headline', false); |
||
|
|||
57 | $headlineLip6 = (bool) self::checkData($data, 'headline_lip6', false); |
||
58 | $aiType = self::validateInteger( |
||
59 | (int) self::checkData($data, 'ai_type', 0) |
||
60 | ); |
||
61 | $identifier = self::validateInteger( |
||
62 | (int) self::checkData($data, 'identifier', null) |
||
63 | ); |
||
64 | return self::createArticle( |
||
65 | $title, |
||
66 | $body, |
||
67 | $source, |
||
68 | $uniqueId, |
||
69 | $typeId, |
||
70 | $categoryId, |
||
71 | $reporter, |
||
72 | $lead, |
||
73 | $tags, |
||
74 | $publishedAt, |
||
75 | $headline, |
||
76 | $headlineLip6, |
||
77 | $aiType, |
||
78 | $identifier |
||
79 | ); |
||
176 |