Total Complexity | 8 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
17 | final class Version20180913205455 extends AbstractMigration |
||
18 | { |
||
19 | /** |
||
20 | */ |
||
21 | public function up(Schema $schema): void |
||
23 | // Nothing to create |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @throws DBALException |
||
28 | */ |
||
29 | public function postUp(Schema $schema): void |
||
30 | { |
||
31 | $qb = $this->connection->createQueryBuilder(); |
||
32 | $qb->select('id', 'remote_addr') |
||
33 | ->from('visits'); |
||
34 | $st = $this->connection->executeQuery($qb->getSQL()); |
||
35 | |||
36 | $qb = $this->connection->createQueryBuilder(); |
||
37 | $qb->update('visits', 'v') |
||
38 | ->set('v.remote_addr', ':obfuscatedAddr') |
||
39 | ->where('v.id=:id'); |
||
40 | |||
41 | while ($row = $st->fetch(PDO::FETCH_ASSOC)) { |
||
|
|||
42 | $addr = $row['remote_addr'] ?? null; |
||
43 | if ($addr === null) { |
||
44 | continue; |
||
45 | } |
||
46 | |||
47 | $qb->setParameters([ |
||
48 | 'id' => $row['id'], |
||
49 | 'obfuscatedAddr' => $this->determineAddress((string) $addr), |
||
50 | ])->execute(); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | private function determineAddress(string $addr): ?string |
||
55 | { |
||
56 | if ($addr === IpAddress::LOCALHOST) { |
||
57 | return $addr; |
||
58 | } |
||
59 | |||
60 | try { |
||
61 | return (string) IpAddress::fromString($addr)->getObfuscatedCopy(); |
||
62 | } catch (InvalidArgumentException $e) { |
||
63 | return null; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | */ |
||
69 | public function down(Schema $schema): void |
||
71 | // Nothing to rollback |
||
72 | } |
||
73 | } |
||
74 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.