Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 68 |
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 namespace VojtaSvoboda\Brands\Components; |
||
46 | public function defineProperties() |
||
47 | { |
||
48 | return [ |
||
49 | 'brandPage' => [ |
||
50 | 'title' => 'Brand page', |
||
51 | 'description' => 'Page for showing brand detail', |
||
52 | 'type' => 'dropdown', |
||
53 | 'default' => 'brand-detail', |
||
54 | ], |
||
55 | 'categoryPage' => [ |
||
56 | 'title' => 'Category page', |
||
57 | 'description' => 'Page for showing brand category', |
||
58 | 'type' => 'dropdown', |
||
59 | 'default' => 'brands', |
||
60 | ], |
||
61 | 'categoryFilter' => [ |
||
62 | 'title' => 'Category slug', |
||
63 | 'description' => 'Show only brands from some category', |
||
64 | 'type' => 'string', |
||
65 | 'default' => '{{ :category }}', |
||
66 | 'group' => 'Category', |
||
67 | ], |
||
68 | 'letterFilter' => [ |
||
69 | 'title' => 'Starts with letter', |
||
70 | 'description' => 'Show only brands starts with this letter', |
||
71 | 'type' => 'string', |
||
72 | 'default' => '{{ :letter }}', |
||
73 | 'group' => 'Letter', |
||
74 | ], |
||
75 | 'perPage' => [ |
||
76 | 'title' => 'Brands per page', |
||
77 | 'description' => 'How many brands show at one page', |
||
78 | 'type' => 'string', |
||
79 | 'validationPattern' => '^[\d]+$', |
||
80 | 'validationMessage' => 'Per page should be numeric value', |
||
81 | 'default' => 24, |
||
82 | 'group' => 'Paginator', |
||
83 | ], |
||
84 | 'sortOrder' => [ |
||
85 | 'title' => 'Sort order', |
||
86 | 'description' => 'If brands will be rendered ascendent or descendent', |
||
87 | 'type' => 'dropdown', |
||
88 | 'default' => 'ASC', |
||
89 | 'group' => 'Paginator', |
||
90 | ], |
||
91 | 'pageNumber' => [ |
||
92 | 'title' => 'Page number', |
||
93 | 'description' => 'Which page should be displayed', |
||
94 | 'type' => 'string', |
||
95 | 'default' => '{{ page }}', |
||
96 | 'group' => 'Paginator', |
||
97 | ], |
||
98 | 'perRow' => [ |
||
99 | 'title' => 'Brands per row (1-12)', |
||
100 | 'description' => 'How many brands show in one row', |
||
101 | 'type' => 'string', |
||
102 | 'validationPattern' => '^[\d]+$', |
||
103 | 'validationMessage' => 'Per row should be numeric value between 1 and 12', |
||
104 | 'default' => 6, |
||
105 | 'group' => 'Layout', |
||
106 | ], |
||
107 | 'logoWidth' => [ |
||
108 | 'title' => 'Logo width', |
||
109 | 'description' => 'Width of the logo in pixels', |
||
110 | 'type' => 'string', |
||
111 | 'validationPattern' => '^[\d]+$', |
||
112 | 'validationMessage' => 'Logo width should be numeric value', |
||
113 | 'default' => 300, |
||
114 | 'group' => 'Layout', |
||
115 | ], |
||
116 | 'logoHeight' => [ |
||
117 | 'title' => 'Logo height', |
||
118 | 'description' => 'Height of the logo in pixels', |
||
119 | 'type' => 'string', |
||
120 | 'validationPattern' => '^[\d]+$', |
||
121 | 'validationMessage' => 'Logo height should be numeric value', |
||
122 | 'default' => 300, |
||
123 | 'group' => 'Layout', |
||
124 | ], |
||
125 | ]; |
||
126 | } |
||
127 | |||
256 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: