| Conditions | 6 |
| Paths | 10 |
| Total Lines | 52 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 139 | public function __construct($additionalData = null) |
||
| 140 | { |
||
| 141 | if ($additionalData !== null) { |
||
| 142 | // You've supplied the class with $additionalData, so, please populate your Credentials data through the |
||
| 143 | // populateCredentials extensions point. It will have access to your $additionalData also |
||
| 144 | $this->invokeWithExtensions('populateCredentials', $additionalData); |
||
| 145 | } else { |
||
| 146 | // Default functionality is to grab Credentials from SiteConfig |
||
| 147 | /** @var SiteConfig $config */ |
||
| 148 | $config = SiteConfig::current_site_config(); |
||
| 149 | |||
| 150 | // You might want to implement this via Environment variables or something. Just make sure SiteConfig has |
||
| 151 | // access to that variable, and return it here |
||
| 152 | $this->setEnabled((bool) $config->relField('SwiftypeEnabled')); |
||
| 153 | |||
| 154 | // If you have multiple Engines per site (maybe you use Fluent with a different Engine on each Locale), then |
||
| 155 | // this provides some basic ability to have different credentials returned based on the application state |
||
| 156 | $this->setEngineSlug($config->relField('SwiftypeEngineSlug')); |
||
| 157 | $this->setDomainID($config->relField('SwiftypeDomainID')); |
||
| 158 | $this->setAPIKey($config->relField('SwiftypeAPIKey')); |
||
| 159 | } |
||
| 160 | |||
| 161 | if (!$this->isEnabled()) { |
||
| 162 | $this->disable( |
||
| 163 | 'Swiftype is disabled. It can be enabled under Settings > Swiftype Search' |
||
| 164 | ); |
||
| 165 | |||
| 166 | return; |
||
| 167 | } |
||
| 168 | |||
| 169 | if (!$this->getEngineSlug()) { |
||
| 170 | $this->disable( |
||
| 171 | 'Swiftype Engine Slug value has not been set. Settings > Swiftype Search > Swiftype Engine Slug' |
||
| 172 | ); |
||
| 173 | |||
| 174 | return; |
||
| 175 | } |
||
| 176 | |||
| 177 | if (!$this->getDomainID()) { |
||
| 178 | $this->disable( |
||
| 179 | 'Swiftype Domain ID has not been set. Settings > Swiftype Search > Swiftype Domain ID' |
||
| 180 | ); |
||
| 181 | |||
| 182 | return; |
||
| 183 | } |
||
| 184 | |||
| 185 | if (!$this->getAPIKey()) { |
||
| 186 | $this->disable( |
||
| 187 | 'Swiftype API Key has not been set. Settings > Swiftype Search > Swiftype Production API Key' |
||
| 188 | ); |
||
| 189 | |||
| 190 | return; |
||
| 191 | } |
||
| 220 |