| Conditions | 3 |
| Paths | 3 |
| Total Lines | 64 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 42 | public function createSpIfNotExists($entityId, $certificate, $sfoEnabled = false) |
||
| 43 | { |
||
| 44 | // Does the SP exist? |
||
| 45 | $stmt = $this->connection->prepare('SELECT * FROM saml_entity WHERE entity_id=:entityId LIMIT 1'); |
||
| 46 | $stmt->bindParam('entityId', $entityId); |
||
| 47 | $stmt->execute(); |
||
| 48 | if ($stmt->rowCount() === 0) { |
||
| 49 | // If not, create it |
||
| 50 | $uuid = Uuid::uuid4()->toString(); |
||
| 51 | $type = 'sp'; |
||
| 52 | $configuration['acs'] = [self::SP_ACS_LOCATION]; |
||
| 53 | $configuration['public_key'] = $certificate; |
||
| 54 | $configuration['loa'] = ['__default__' => 'http://dev.openconext.local/assurance/loa1']; |
||
| 55 | $configuration['second_factor_only'] = $sfoEnabled; |
||
| 56 | $configuration['set_sso_cookie_on_2fa'] = true; |
||
| 57 | $configuration['allow_sso_on_2fa'] = true; |
||
| 58 | $configuration['second_factor_only_nameid_patterns'] = [ |
||
| 59 | 'urn:collab:person:stepup.example.com:admin', |
||
| 60 | 'urn:collab:person:dev.openconext.local:*', |
||
| 61 | ]; |
||
| 62 | |||
| 63 | $data = [ |
||
| 64 | 'entityId' => $entityId, |
||
| 65 | 'type' => $type, |
||
| 66 | 'configuration' => json_encode($configuration), |
||
| 67 | 'id' => $uuid, |
||
| 68 | ]; |
||
| 69 | $sql = <<<SQL |
||
| 70 | INSERT INTO saml_entity ( |
||
| 71 | `entity_id`, |
||
| 72 | `type`, |
||
| 73 | `configuration`, |
||
| 74 | `id` |
||
| 75 | ) |
||
| 76 | VALUES ( |
||
| 77 | :entityId, |
||
| 78 | :type, |
||
| 79 | :configuration, |
||
| 80 | :id |
||
| 81 | ) |
||
| 82 | SQL; |
||
| 83 | $stmt = $this->connection->prepare($sql); |
||
| 84 | if ($stmt->execute($data)) { |
||
| 85 | return $data; |
||
| 86 | } |
||
| 87 | |||
| 88 | throw new Exception( |
||
| 89 | sprintf( |
||
| 90 | 'Unable to insert the new SP saml_entity. PDO raised this error: "%s"', |
||
| 91 | $stmt->errorInfo()[2] |
||
| 92 | ) |
||
| 93 | ); |
||
| 94 | } else { |
||
| 95 | // Return the SP data |
||
| 96 | $results = $stmt->fetchAll(); |
||
| 97 | $result = $results[0]; |
||
| 98 | $data = [ |
||
| 99 | 'entityId' => $result['entity_id'], |
||
| 100 | 'type' => $result['type'], |
||
| 101 | 'configuration' => $result['configuration'], |
||
| 102 | 'id' => $result['id'], |
||
| 103 | ]; |
||
| 104 | |||
| 105 | return $data; |
||
| 106 | } |
||
| 167 |
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