| Conditions | 3 |
| Paths | 3 |
| Total Lines | 55 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 109 | public function createIdpIfNotExists($entityId, $certificate) |
||
| 110 | { |
||
| 111 | // Does the SP exist? |
||
| 112 | $stmt = $this->connection->prepare('SELECT * FROM saml_entity WHERE entity_id=:entityId LIMIT 1'); |
||
| 113 | $stmt->bindParam('entityId', $entityId, PDO::PARAM_STR); |
||
| 114 | $stmt->execute(); |
||
| 115 | if ($stmt->rowCount() === 0) { |
||
| 116 | // If not, create it |
||
| 117 | $uuid = Uuid::uuid4()->toString(); |
||
| 118 | $type = 'idp'; |
||
| 119 | |||
| 120 | $configuration['public_key'] = $certificate; |
||
| 121 | |||
| 122 | $data = [ |
||
| 123 | 'entityId' => $entityId, |
||
| 124 | 'type' => $type, |
||
| 125 | 'configuration' => json_encode($configuration), |
||
| 126 | 'id' => $uuid, |
||
| 127 | ]; |
||
| 128 | $sql = <<<SQL |
||
| 129 | INSERT INTO saml_entity ( |
||
| 130 | `entity_id`, |
||
| 131 | `type`, |
||
| 132 | `configuration`, |
||
| 133 | `id` |
||
| 134 | ) |
||
| 135 | VALUES ( |
||
| 136 | :entityId, |
||
| 137 | :type, |
||
| 138 | :configuration, |
||
| 139 | :id |
||
| 140 | ) |
||
| 141 | SQL; |
||
| 142 | $stmt = $this->connection->prepare($sql); |
||
| 143 | if ($stmt->execute($data)) { |
||
| 144 | return $data; |
||
| 145 | } |
||
| 146 | |||
| 147 | throw new Exception( |
||
| 148 | sprintf( |
||
| 149 | 'Unable to insert the new SP saml_entity. PDO raised this error: "%s"', |
||
| 150 | $stmt->errorInfo()[2] |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | } else { |
||
| 154 | // Return the SP data |
||
| 155 | $results = $stmt->fetchAll(); |
||
| 156 | $result = $results[0]; |
||
| 157 | $data = [ |
||
| 158 | 'entityId' => $result['entity_id'], |
||
| 159 | 'type' => $result['type'], |
||
| 160 | 'configuration' => $result['configuration'], |
||
| 161 | 'id' => $result['id'], |
||
| 162 | ]; |
||
| 163 | return $data; |
||
| 164 | } |
||
| 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