Conditions | 20 |
Paths | 119 |
Total Lines | 56 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 1 | Features | 5 |
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 |
||
54 | function run($request) { |
||
55 | increase_time_limit_to(); |
||
56 | $self = get_class($this); |
||
57 | $verbose = isset($_GET['verbose']); |
||
58 | |||
59 | if (isset($_GET['class']) && isset($_GET['id'])) { |
||
60 | $item = DataObject::get($_GET['class'])->byID($_GET['id']); |
||
61 | if (!$item || !$item->exists()) die('not found: ' . $_GET['id']); |
||
62 | $item->rebuildVFI(); |
||
63 | echo "done"; |
||
64 | return; |
||
65 | } |
||
66 | |||
67 | if (isset($_GET['link'])) { |
||
68 | $item = SiteTree::get_by_link($_GET['link']); |
||
69 | if (!$item || !$item->exists()) die('not found: ' . $_GET['link']); |
||
70 | $item->rebuildVFI(); |
||
71 | echo "done"; |
||
72 | return; |
||
73 | } |
||
74 | |||
75 | if (isset($_GET['start'])) { |
||
76 | $this->runFrom($_GET['class'], $_GET['start'], $_GET['field']); |
||
77 | } |
||
78 | else { |
||
79 | foreach(array('framework','sapphire') as $dirname) { |
||
80 | $script = sprintf("%s%s$dirname%scli-script.php", BASE_PATH, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); |
||
81 | if(file_exists($script)) { |
||
82 | break; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | $classes = VirtualFieldIndex::get_classes_with_vfi(); |
||
87 | foreach ($classes as $class) { |
||
88 | if (isset($_GET['class']) && $class != $_GET['class']) continue; |
||
89 | $singleton = singleton($class); |
||
90 | $query = $singleton->get($class); |
||
91 | $dtaQuery = $query->dataQuery(); |
||
92 | $sqlQuery = $dtaQuery->getFinalisedQuery(); |
||
93 | $singleton->extend('augmentSQL',$sqlQuery,$dtaQuery); |
||
94 | $total = $query->count(); |
||
95 | $startFrom = isset($_GET['startfrom']) ? $_GET['startfrom'] : 0; |
||
96 | $field = isset($_GET['field']) ? $_GET['field'] : ''; |
||
97 | |||
98 | echo "Class: $class, total: $total\n\n"; |
||
99 | |||
100 | for ($offset = $startFrom; $offset < $total; $offset += $this->stat('recordsPerRequest')) { |
||
101 | echo "$offset.."; |
||
102 | $cmd = "php $script dev/tasks/$self class=$class start=$offset field=$field"; |
||
103 | if($verbose) echo "\n Running '$cmd'\n"; |
||
104 | $res = $verbose ? passthru($cmd) : `$cmd`; |
||
105 | if($verbose) echo " ".preg_replace('/\r\n|\n/', '$0 ', $res)."\n"; |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | |||
119 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.