Conditions | 9 |
Paths | 42 |
Total Lines | 52 |
Code Lines | 31 |
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 |
||
24 | public function run($request) |
||
25 | { |
||
26 | $themeBlocksPath = Director::baseFolder() . DIRECTORY_SEPARATOR . $this->getThemeDir() . '/templates/Blocks'; |
||
27 | $mysiteBlocksPath = Director::baseFolder() . DIRECTORY_SEPARATOR . project() . '/templates/Blocks'; |
||
28 | |||
29 | $classes = Block::listTemplates(); |
||
30 | |||
31 | $files = []; |
||
32 | $files = array_merge($files, glob($themeBlocksPath . '/*.ss')); |
||
33 | $files = array_merge($files, glob($mysiteBlocksPath . '/*.ss')); |
||
34 | |||
35 | if (empty($files)) { |
||
36 | $this->message("No blocks found"); |
||
37 | $this->message("Please make sure you have blocks in $themeBlocksPath or in $mysiteBlocksPath"); |
||
38 | } |
||
39 | |||
40 | $classCreated = false; |
||
41 | $allBlocks = []; |
||
42 | $scssDir = dirname($this->getScssFolder(true)); |
||
43 | |||
44 | foreach ($files as $file) { |
||
45 | $content = file_get_contents($file); |
||
46 | |||
47 | // Check for lost $Content variable |
||
48 | if (strpos($content, '$Content') !== false) { |
||
49 | throw new Exception("Blocks cannot nest Content"); |
||
50 | } |
||
51 | |||
52 | $result = $this->createBlockClass($file, $classes); |
||
53 | if ($result) { |
||
54 | $classCreated = true; |
||
55 | } |
||
56 | if (is_dir($scssDir)) { |
||
57 | $result = $this->createStyles($file); |
||
58 | } |
||
59 | $allBlocks[] = pathinfo($file, PATHINFO_FILENAME); |
||
60 | } |
||
61 | |||
62 | |||
63 | if (is_dir($scssDir)) { |
||
64 | $this->message("Refresh all styles"); |
||
65 | $scssFile = $scssDir . '/_blocks.scss'; |
||
66 | $data = '/* This file is automatically generated */' . "\n"; |
||
67 | foreach ($allBlocks as $blockName) { |
||
68 | $data .= '@import "blocks/' . $blockName . '";' . "\n"; |
||
69 | } |
||
70 | file_put_contents($scssFile, $data); |
||
71 | } |
||
72 | |||
73 | // A new class was added, regenerate the manifest |
||
74 | if ($classCreated) { |
||
75 | $this->regenerateClassManifest(); |
||
76 | } |
||
224 |