Conditions | 4 |
Paths | 6 |
Total Lines | 55 |
Code Lines | 29 |
Lines | 6 |
Ratio | 10.91 % |
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 |
||
25 | public function setUp() { |
||
|
|||
26 | $cache = SS_Cache::factory('elasticsearch'); |
||
27 | $cache->clean(Zend_Cache::CLEANING_MODE_ALL); |
||
28 | SS_Cache::set_cache_lifetime('elasticsearch', 3600, 1000); |
||
29 | |||
30 | // this needs to be called in order to create the list of searchable |
||
31 | // classes and fields that are available. Simulates part of a build |
||
32 | $classes = array('SearchableTestPage','SiteTree','Page','FlickrPhotoTO','FlickrSetTO', |
||
33 | 'FlickrTagTO', 'FlickrAuthorTO'); |
||
34 | $this->requireDefaultRecordsFrom = $classes; |
||
35 | |||
36 | // add Searchable extension where appropriate |
||
37 | FlickrSetTO::add_extension('SilverStripe\Elastica\Searchable'); |
||
38 | FlickrPhotoTO::add_extension('SilverStripe\Elastica\Searchable'); |
||
39 | FlickrTagTO::add_extension('SilverStripe\Elastica\Searchable'); |
||
40 | FlickrAuthorTO::add_extension('SilverStripe\Elastica\Searchable'); |
||
41 | SearchableTestPage::add_extension('SilverStripe\Elastica\Searchable'); |
||
42 | |||
43 | // clear the index |
||
44 | $this->service = Injector::inst()->create('SilverStripe\Elastica\ElasticaService'); |
||
45 | $this->service->setTestMode(true); |
||
46 | |||
47 | // A previous test may have deleted the index and then failed, so check for this |
||
48 | if (!$this->service->getIndex()->exists()) { |
||
49 | $this->service->getIndex()->create(); |
||
50 | } |
||
51 | $this->service->reset(); |
||
52 | |||
53 | // FIXME - use request getVar instead? |
||
54 | $_GET['progress'] = 20; |
||
55 | // load fixtures |
||
56 | |||
57 | $orig_fixture_file = static::$fixture_file; |
||
58 | |||
59 | View Code Duplication | foreach (static::$ignoreFixtureFileFor as $testPattern) { |
|
60 | $pattern = '/'.$testPattern.'/'; |
||
61 | if (preg_match($pattern, $this->getName())) { |
||
62 | static::$fixture_file = null; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | parent::setUp(); |
||
67 | static::$fixture_file = $orig_fixture_file; |
||
68 | |||
69 | $this->publishSiteTree(); |
||
70 | |||
71 | $this->service->reset(); |
||
72 | |||
73 | // index loaded fixtures |
||
74 | $task = new ReindexTask($this->service); |
||
75 | // null request is fine as no parameters used |
||
76 | |||
77 | $task->run(null); |
||
78 | |||
79 | } |
||
80 | |||
173 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: