| Conditions | 5 |
| Paths | 12 |
| Total Lines | 100 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 11 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 81 | public function updateCMSFields(FieldList $fields) |
||
| 82 | { |
||
| 83 | $owner = $this->getOwner(); |
||
| 84 | $name = '[none]'; |
||
| 85 | if (class_exists((string) $owner->ClassNameLastEdited)) { |
||
| 86 | $name = Injector::inst()->get($owner->ClassNameLastEdited)->i18n_singular_name(); |
||
| 87 | } |
||
| 88 | |||
| 89 | // page caching |
||
| 90 | $fields->addFieldsToTab( |
||
| 91 | 'Root.Caching', |
||
| 92 | [ |
||
| 93 | HeaderField::create('FullPageCachingHeader', 'Full Page Caching'), |
||
| 94 | CheckboxField::create('HasCaching', 'Allow caching of entire pages?') |
||
| 95 | ->setDescription( |
||
| 96 | 'You will also need to set up the cache time below for it to be enabled. |
||
| 97 | You can set a default time below, but you can also set the time for individual pages.' |
||
| 98 | ), |
||
| 99 | ] |
||
| 100 | ); |
||
| 101 | if ($owner->HasCaching) { |
||
| 102 | $fields->addFieldsToTab( |
||
| 103 | 'Root.Caching', |
||
| 104 | [ |
||
| 105 | NumericField::create('PublicCacheDurationInSeconds', 'Cache time for ALL pages') |
||
| 106 | ->setDescription( |
||
| 107 | 'USE WITH CARE - This will apply caching to ALL pages on the site. |
||
| 108 | Time is in seconds (e.g. 600 = 10 minutes). |
||
| 109 | Cache time on individual pages will override this value set here. |
||
| 110 | The total number of pages on the site with an individual caching time is: ' . Page::get()->filter('PublicCacheDurationInSeconds:GreaterThan', 0)->count() |
||
| 111 | ), |
||
| 112 | ] |
||
| 113 | ); |
||
| 114 | } |
||
| 115 | |||
| 116 | //partial caching |
||
| 117 | $fields->addFieldsToTab( |
||
| 118 | 'Root.Caching', |
||
| 119 | [ |
||
| 120 | HeaderField::create('PartialCachingHeader', 'Partial Caching'), |
||
| 121 | CheckboxField::create('HasPartialCaching', 'Allow partial template caching?') |
||
| 122 | ->setDescription( |
||
| 123 | 'This should usually be turned on unless you want to make sure no templates are cached in any part at all.' |
||
| 124 | ), |
||
| 125 | ] |
||
| 126 | ); |
||
| 127 | if ($owner->HasPartialCaching) { |
||
| 128 | $fields->addFieldsToTab( |
||
| 129 | 'Root.Caching', |
||
| 130 | [ |
||
| 131 | CheckboxField::create('RecordCacheUpdates', 'Keep a record of what is being changed?') |
||
| 132 | ->setDescription( |
||
| 133 | 'To work out when the cache is being cleared, |
||
| 134 | you can keep a record of the last ' . self::MAX_OBJECTS_UPDATED . ' records changed. |
||
| 135 | Only turn this on temporarily for tuning purposes.' |
||
| 136 | ), |
||
| 137 | ] |
||
| 138 | ); |
||
| 139 | if ($this->getOwner()->RecordCacheUpdates) { |
||
| 140 | $fields->addFieldsToTab( |
||
| 141 | 'Root.Caching', |
||
| 142 | [ |
||
| 143 | |||
| 144 | ReadonlyField::create('CacheKeyLastEditedNice', 'Last database change', $owner->dbObject('CacheKeyLastEdited')->ago()) |
||
| 145 | ->setDescription( |
||
| 146 | 'The frontend template cache will be invalidated every time this value changes. |
||
| 147 | The value changes every time anything is changed in the database.' |
||
| 148 | ), |
||
| 149 | ReadonlyField::create('ClassNameLastEditedNice', 'Last record updated', $name) |
||
| 150 | ->setDescription('The last record to invalidate the cache.'), |
||
| 151 | |||
| 152 | GridField::create( |
||
| 153 | 'ObjectsUpdated', |
||
| 154 | 'Last ' . self::MAX_OBJECTS_UPDATED . ' records updated', |
||
| 155 | ObjectsUpdated::get()->limit(self::MAX_OBJECTS_UPDATED), |
||
| 156 | GridFieldConfig_RecordViewer::create() |
||
| 157 | ) |
||
| 158 | ->setDescription( |
||
| 159 | ' |
||
| 160 | This is a list of the last ' . self::MAX_OBJECTS_UPDATED . ' records updated. |
||
| 161 | It is used to track changes to the database. |
||
| 162 | It includes: ' . ObjectsUpdated::classes_edited() |
||
| 163 | ), |
||
| 164 | ] |
||
| 165 | ); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | // resource caching |
||
| 169 | $fields->addFieldsToTab( |
||
| 170 | 'Root.Caching', |
||
| 171 | [ |
||
| 172 | HeaderField::create('ResourceCachingHeader', 'Resource Caching'), |
||
| 173 | CheckboxField::create('HasResourceCaching', 'Allow caching of resources (e.g. images, styles, etc.). ') |
||
| 174 | ->setDescription( |
||
| 175 | 'This will add cache control headers to your .htaccess file for images, styles, and scripts. |
||
| 176 | This will help with performance, but once cached, a cache can not be cleared without changing the file name.' |
||
| 177 | ), |
||
| 178 | NumericField::create('ResourceCachingTimeInSeconds', 'Cache time for resources') |
||
| 179 | ->setDescription( |
||
| 180 | 'Time is in seconds (e.g. 600 = 10 minutes, 86400 = 1 day). |
||
| 181 | This will be used for all resources on the site (fonts, images, styles, and scripts).' |
||
| 325 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths