Conditions | 20 |
Paths | 2081 |
Total Lines | 94 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
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 |
||
75 | public function init($tag, $attrs) |
||
|
|||
76 | { |
||
77 | $def = null; |
||
78 | $name = null; |
||
79 | $id = null; |
||
80 | $desc = null; |
||
81 | $baseDir = null; |
||
82 | $ver = null; |
||
83 | $strict = null; |
||
84 | |||
85 | // some shorthands |
||
86 | $project = $this->configurator->project; |
||
87 | $buildFileParent = $this->configurator->buildFileParent; |
||
88 | |||
89 | foreach ($attrs as $key => $value) { |
||
90 | if ('default' === $key) { |
||
91 | $def = $value; |
||
92 | } elseif ('name' === $key) { |
||
93 | $name = $value; |
||
94 | } elseif ('id' === $key) { |
||
95 | $id = $value; |
||
96 | } elseif ('basedir' === $key) { |
||
97 | $baseDir = $value; |
||
98 | } elseif ('description' === $key) { |
||
99 | $desc = $value; |
||
100 | } elseif ('phingVersion' === $key) { |
||
101 | $ver = $value; |
||
102 | } elseif ('strict' === $key) { |
||
103 | $strict = $value; |
||
104 | } else { |
||
105 | throw new ExpatParseException("Unexpected attribute '{$key}'"); |
||
106 | } |
||
107 | } |
||
108 | // these things get done no matter what |
||
109 | if (null == $name) { |
||
110 | $name = basename($this->configurator->getBuildFile()); |
||
111 | } |
||
112 | |||
113 | $canonicalName = self::canonicalName($name); |
||
114 | $this->configurator->setCurrentProjectName($canonicalName); |
||
115 | $path = (string) $this->configurator->getBuildFile(); |
||
116 | $project->setUserProperty("phing.file.{$canonicalName}", $path); |
||
117 | $project->setUserProperty("phing.dir.{$canonicalName}", dirname($path)); |
||
118 | |||
119 | if ($this->configurator->isIgnoringProjectTag()) { |
||
120 | return; |
||
121 | } |
||
122 | |||
123 | if (null === $def) { |
||
124 | throw new ExpatParseException( |
||
125 | 'The default attribute of project is required' |
||
126 | ); |
||
127 | } |
||
128 | |||
129 | $project->setDefaultTarget($def); |
||
130 | |||
131 | if (null !== $name) { |
||
132 | $project->setName($name); |
||
133 | $project->addReference($name, $project); |
||
134 | } |
||
135 | |||
136 | if (null !== $id) { |
||
137 | $project->addReference($id, $project); |
||
138 | } |
||
139 | |||
140 | if (null !== $desc) { |
||
141 | $project->setDescription($desc); |
||
142 | } |
||
143 | |||
144 | if (null !== $ver) { |
||
145 | $project->setPhingVersion($ver); |
||
146 | } |
||
147 | |||
148 | if (null !== $strict) { |
||
149 | $project->setStrictMode(StringHelper::booleanValue($strict)); |
||
150 | } |
||
151 | |||
152 | if (null !== $project->getProperty('project.basedir')) { |
||
153 | $project->setBasedir($project->getProperty('project.basedir')); |
||
154 | } else { |
||
155 | if (null === $baseDir) { |
||
156 | $project->setBasedir($buildFileParent->getAbsolutePath()); |
||
157 | } else { |
||
158 | // check whether the user has specified an absolute path |
||
159 | $f = new File($baseDir); |
||
160 | if ($f->isAbsolute()) { |
||
161 | $project->setBasedir($baseDir); |
||
162 | } else { |
||
163 | $project->setBaseDir($project->resolveFile($baseDir, $buildFileParent)); |
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | |||
168 | $project->addTarget('', $this->context->getImplicitTarget()); |
||
169 | } |
||
209 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.