Conditions | 11 |
Paths | 136 |
Total Lines | 62 |
Code Lines | 26 |
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 |
||
84 | new TableRelation('structurefield', 'material', 'materialfield.MaterialID'); |
||
85 | new TableRelation('structure', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'parent_id', 'children_relations'); |
||
1 ignored issue
–
show
|
|||
86 | new TableRelation('structure', 'structure', 'children_relations.child_id', TableRelation::T_ONE_TO_MANY, 'StructureID', 'children'); |
||
1 ignored issue
–
show
|
|||
87 | new TableRelation('structure', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'child_id', 'parents_relations'); |
||
1 ignored issue
–
show
|
|||
88 | new TableRelation('structure', 'structure', 'parents_relations.parent_id', TableRelation::T_ONE_TO_MANY, 'StructureID', 'parents'); |
||
1 ignored issue
–
show
|
|||
89 | new TableRelation('structurematerial', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'parent_id'); |
||
1 ignored issue
–
show
|
|||
90 | new TableRelation('groupright', 'right', 'RightID', TableRelation::T_ONE_TO_MANY); |
||
91 | //elapsed('CMS:prepare'); |
||
92 | |||
93 | // Все прошло успешно |
||
94 | return true && parent::prepare(); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Handler for CMSAPI database version manipulating |
||
99 | * @param string $to_version Version to switch to |
||
100 | * @return string Current database version |
||
101 | */ |
||
102 | public function migrator($to_version = null) |
||
103 | { |
||
104 | // If something passed - change database version to it |
||
105 | if (func_num_args()) { |
||
106 | // Save current version to special db table |
||
107 | db()->query("ALTER TABLE `" . dbMySQLConnector::$prefix . "cms_version` CHANGE `version` `version` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '" . $to_version . "';"); |
||
1 ignored issue
–
show
|
|||
108 | die('Database successfully migrated to [' . $to_version . ']'); |
||
109 | } else { // Return current database version |
||
1 ignored issue
–
show
|
|||
110 | $version_row = db()->fetch('SHOW COLUMNS FROM `' . dbMySQLConnector::$prefix . 'cms_version`'); |
||
111 | return $version_row[0]['Default']; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | /** @see \samson\core\CompressableExternalModule::afterCompress() */ |
||
116 | public function afterCompress(& $obj = null, array & $code = null) |
||
117 | { |
||
118 | // Fill additional fields data to material db request data for automatic altering material request |
||
119 | self::$fields = array(); |
||
120 | |||
121 | $t_name = '_mf'; |
||
122 | |||
123 | // Save original material attributes |
||
124 | self::$materialAttributes = &Material::$_attributes; |
||
125 | |||
126 | // Copy original material table attributes |
||
127 | Material::$_attributes = \samson\activerecord\material::$_attributes; |
||
128 | Material::$_sql_select = \samson\activerecord\material::$_sql_select; |
||
129 | Material::$_sql_from = \samson\activerecord\material::$_sql_from; |
||
130 | Material::$_own_group = \samson\activerecord\material::$_own_group; |
||
131 | Material::$_map = \samson\activerecord\material::$_map; |
||
132 | |||
133 | // Perform db query to get all possible material fields |
||
134 | if (dbQuery('field')->Active(1)->Name('', dbRelation::NOT_EQUAL)->exec($this->material_fields)) foreach ($this->material_fields as $db_field) { |
||
135 | // Add additional field localization condition |
||
136 | if ($db_field->local == 1) $equal = '((' . $t_name . '.FieldID = ' . $db_field->id . ')&&(' . $t_name . ".locale = '" . locale() . "'))"; |
||
137 | else $equal = '((' . $t_name . '.FieldID = ' . $db_field->id . ')&&(' . $t_name . ".locale = ''))"; |
||
138 | |||
139 | // Define field value DB column for storing data |
||
140 | $v_col = 'Value'; |
||
141 | // We must get data from other column for this type of field |
||
142 | if ($db_field->Type == 7 || $db_field->Type == 3 || $db_field->Type == 10) { |
||
143 | $v_col = 'numeric_value'; |
||
144 | } else if ($db_field->Type == 6) { |
||
145 | $v_col = 'key_value'; |
||
146 | } |
||
172 |
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: