Conditions | 9 |
Paths | 14 |
Total Lines | 59 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 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 |
||
21 | public function requireDefaultRecords() |
||
22 | { |
||
23 | parent::requireDefaultRecords(); |
||
24 | |||
25 | // verbose messages |
||
26 | DB::alteration_message('Searching for environment configuration for ' . Director::absoluteURL('/'), 'created'); |
||
27 | |||
28 | // get the config based on the URL (URL is key) |
||
29 | $config = $this->prepConfig($this->config()->get('environments'), Director::absoluteURL('/')); |
||
30 | |||
31 | // only run if everything is fine |
||
32 | if (!is_array($config) || empty($config)) { |
||
33 | DB::alteration_message('No configuration found.', 'created'); |
||
34 | } else if (!file_exists('../' . $config['filename'])) { |
||
35 | DB::alteration_message('No CHANGELOG.md-file found.', 'created'); |
||
36 | } else { |
||
37 | DB::alteration_message($config['environment_name'] . ' identified.', 'created'); |
||
38 | |||
39 | // get the information in the database for the last release notification |
||
40 | $record = (self::get()->count() == 0) ? new self() : self::get()->first(); |
||
41 | |||
42 | // load the changelog and prep it by removing the first few lines |
||
43 | $changelog = trim(preg_replace('/^(.*\n){4}/', '', file_get_contents('../' . $config['filename']))); |
||
44 | |||
45 | // check if the CHANGELOG.md file has been changed since the last run |
||
46 | if ($changelog == '') { |
||
47 | DB::alteration_message('No change identified.', 'created'); |
||
48 | } else if (md5($changelog) != md5($record->Changelog)) { |
||
49 | // email the changelog out |
||
50 | foreach ($config['recipients'] as $recipient) { |
||
51 | Email::create( |
||
52 | $config['from'], |
||
53 | $recipient, |
||
54 | $config['subject'], |
||
55 | |||
56 | // remove the old part and add more useful information to the content |
||
57 | sprintf( |
||
58 | "%s (%s)\n\n%s", |
||
59 | $config['environment_name'], |
||
60 | $config['url'], |
||
61 | $changelog |
||
62 | ) |
||
63 | )->sendPlain(); |
||
64 | |||
65 | DB::alteration_message($recipient . ' notified', 'created'); |
||
66 | } |
||
67 | |||
68 | // save the new changelog to ensure we aren't re-running this in the next step |
||
69 | $record->Changelog = $changelog; |
||
70 | } |
||
71 | |||
72 | // say welcome :) |
||
73 | if (!$record->ID) { |
||
74 | DB::alteration_message('Install of FriendsOfSilverStripe/release-notifications'); |
||
75 | } |
||
76 | |||
77 | $record->write(); |
||
78 | } |
||
79 | } |
||
80 | |||
105 |
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.