Conditions | 2 |
Paths | 2 |
Total Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
25 | public function createSp($entityId, $certificate, $sfoEnabled = false) |
||
26 | { |
||
27 | $uuid = Uuid::uuid4()->toString(); |
||
28 | $type = 'sp'; |
||
29 | $configuration['acs'] = [self::SP_ACS_LOCATION]; |
||
|
|||
30 | $configuration['public_key'] = $certificate; |
||
31 | $configuration['loa'] = ['__default__' => 'http://stepup.example.com/assurance/loa1']; |
||
32 | $configuration['second_factor_only'] = $sfoEnabled; |
||
33 | $configuration['second_factor_only_nameid_patterns'] = [ |
||
34 | 'urn:collab:person:stepup.example.com:admin', |
||
35 | 'urn:collab:person:stepup.example.com:*', |
||
36 | ]; |
||
37 | |||
38 | $data = [ |
||
39 | 'entityId' => $entityId, |
||
40 | 'type' => $type, |
||
41 | 'configuration' => json_encode($configuration), |
||
42 | 'id' => $uuid, |
||
43 | ]; |
||
44 | $sql = <<<SQL |
||
45 | INSERT INTO saml_entity ( |
||
46 | `entity_id`, |
||
47 | `type`, |
||
48 | `configuration`, |
||
49 | `id` |
||
50 | ) |
||
51 | VALUES ( |
||
52 | :entityId, |
||
53 | :type, |
||
54 | :configuration, |
||
55 | :id |
||
56 | ) |
||
57 | SQL; |
||
58 | $stmt = $this->connection->prepare($sql); |
||
59 | if ($stmt->execute($data)) { |
||
60 | return $data; |
||
61 | } |
||
62 | |||
63 | throw new Exception('Unable to insert the new SP saml_entity'); |
||
64 | } |
||
65 | } |
||
66 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.