aviat4ion /
Query
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php declare(strict_types=1); |
||
| 2 | /** |
||
| 3 | * Query |
||
| 4 | * |
||
| 5 | * SQL Query Builder / Database Abstraction Layer |
||
| 6 | * |
||
| 7 | * PHP version 7.1 |
||
| 8 | * |
||
| 9 | * @package Query |
||
| 10 | * @author Timothy J. Warren <[email protected]> |
||
| 11 | * @copyright 2012 - 2018 Timothy J. Warren |
||
| 12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
||
| 13 | * @link https://git.timshomepage.net/aviat4ion/Query |
||
| 14 | */ |
||
| 15 | namespace Query\Drivers\Pgsql; |
||
| 16 | |||
| 17 | use Query\Drivers\AbstractDriver; |
||
| 18 | use Query\Drivers\DriverInterface; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * PostgreSQL specific class |
||
| 22 | */ |
||
| 23 | class Driver extends AbstractDriver implements DriverInterface { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Connect to a PosgreSQL database |
||
| 27 | * |
||
| 28 | * @codeCoverageIgnore |
||
| 29 | * @param string $dsn |
||
| 30 | * @param string $username |
||
| 31 | * @param string $password |
||
| 32 | * @param array $options |
||
| 33 | */ |
||
| 34 | public function __construct($dsn, $username=NULL, $password=NULL, array $options=[]) |
||
| 35 | { |
||
| 36 | if (strpos($dsn, 'pgsql') === FALSE) |
||
| 37 | { |
||
| 38 | $dsn = 'pgsql:'.$dsn; |
||
| 39 | } |
||
| 40 | |||
| 41 | parent::__construct($dsn, $username, $password, $options); |
||
| 42 | } |
||
| 43 | |||
| 44 | // -------------------------------------------------------------------------- |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get a list of schemas for the current connection |
||
| 48 | * |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | public function getSchemas(): ?array |
||
| 52 | { |
||
| 53 | $sql = <<<SQL |
||
| 54 | SELECT DISTINCT "schemaname" FROM "pg_tables" |
||
| 55 | WHERE "schemaname" NOT LIKE 'pg\_%' |
||
| 56 | AND "schemaname" != 'information_schema' |
||
| 57 | SQL; |
||
| 58 | |||
| 59 | return $this->driverQuery($sql); |
||
| 60 | } |
||
| 61 | |||
| 62 | // -------------------------------------------------------------------------- |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Retrieve foreign keys for the table |
||
| 66 | * |
||
| 67 | * @param string $table |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | public function getFks($table): array |
||
| 71 | { |
||
| 72 | $valueMap = [ |
||
| 73 | 'c' => 'CASCADE', |
||
| 74 | 'r' => 'RESTRICT', |
||
| 75 | ]; |
||
| 76 | |||
| 77 | $keys = parent::getFks($table); |
||
| 78 | |||
| 79 | foreach($keys as &$key) |
||
|
0 ignored issues
–
show
|
|||
| 80 | { |
||
| 81 | foreach(['update', 'delete'] AS $type) |
||
| 82 | { |
||
| 83 | if ( ! isset($valueMap[$key[$type]])) continue; |
||
| 84 | |||
| 85 | |||
| 86 | $key[$type] = $valueMap[$key[$type]]; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | return $keys; |
||
| 91 | } |
||
| 92 | } |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.