Conditions | 4 |
Paths | 6 |
Total Lines | 71 |
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 |
||
34 | public function transform(ProjectDescriptor $project, Transformation $transformation) |
||
35 | { |
||
36 | $artifact = $transformation->getTransformer()->getTarget() |
||
37 | . DIRECTORY_SEPARATOR |
||
38 | . ($transformation->getArtifact() |
||
39 | ?: 'source'); |
||
40 | |||
41 | /** @var FileDescriptor $file */ |
||
42 | foreach ($project->getFiles() as $file) { |
||
43 | $filename = $file->getPath(); |
||
44 | $source = $file->getSource(); |
||
45 | |||
46 | $root = str_repeat('../', count(explode(DIRECTORY_SEPARATOR, $filename))); |
||
47 | $path = $artifact . DIRECTORY_SEPARATOR . $filename; |
||
48 | if (!file_exists(dirname($path))) { |
||
49 | mkdir(dirname($path), 0755, true); |
||
50 | } |
||
51 | |||
52 | $source = htmlentities($source); |
||
53 | file_put_contents( |
||
54 | $path . '.html', |
||
55 | <<<HTML |
||
56 | <html> |
||
57 | <head> |
||
58 | <script |
||
59 | type="text/javascript" |
||
60 | src="{$root}js/jquery-1.4.2.min.js"> |
||
61 | </script> |
||
62 | <script |
||
63 | type="text/javascript" |
||
64 | src="{$root}syntax_highlighter/scripts/shCore.js"> |
||
65 | </script> |
||
66 | <script |
||
67 | type="text/javascript" |
||
68 | src="{$root}syntax_highlighter/scripts/shBrushJScript.js"> |
||
69 | </script> |
||
70 | <script |
||
71 | type="text/javascript" |
||
72 | src="{$root}syntax_highlighter/scripts/shBrushPhp.js"> |
||
73 | </script> |
||
74 | <script |
||
75 | type="text/javascript" |
||
76 | src="{$root}syntax_highlighter/scripts/shBrushXml.js"> |
||
77 | </script> |
||
78 | <link |
||
79 | href="{$root}syntax_highlighter/styles/shCore.css" rel="stylesheet" |
||
80 | type="text/css" |
||
81 | /> |
||
82 | <link |
||
83 | href="{$root}syntax_highlighter/styles/shCoreEclipse.css" |
||
84 | rel="stylesheet" type="text/css" |
||
85 | /> |
||
86 | <link |
||
87 | href="{$root}syntax_highlighter/styles/shThemeWordpress.css" |
||
88 | rel="stylesheet" type="text/css" |
||
89 | /> |
||
90 | </head> |
||
91 | <body> |
||
92 | <pre class="brush: php">${source}</pre> |
||
93 | <script type="text/javascript"> |
||
94 | SyntaxHighlighter.all(); |
||
95 | jQuery('.gutter div').each(function(key, data){ |
||
96 | jQuery(data).prepend('<a name="L'+jQuery(data).text()+'"/>'); |
||
97 | }); |
||
98 | </script> |
||
99 | </body> |
||
100 | </html> |
||
101 | HTML |
||
102 | ); |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 |