| Conditions | 4 |
| Paths | 2 |
| Total Lines | 26 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | public function __construct( \PDO $pdo, WorldInterface $world = null, $worlds_table = null ) |
||
| 18 | { |
||
| 19 | $this->worlds = new \ArrayObject; |
||
| 20 | $this->worlds_table = $worlds_table ?: $this->worlds_table; |
||
| 21 | |||
| 22 | // ID is listed twice here in order to use it with FETCH_UNIQUE as array key |
||
| 23 | $sql = "SELECT |
||
| 24 | id, |
||
| 25 | id AS id, |
||
| 26 | world_name AS name, |
||
| 27 | world_description AS description, |
||
| 28 | world_url AS slug, |
||
| 29 | world_photo AS photo |
||
| 30 | |||
| 31 | FROM {$this->worlds_table} |
||
| 32 | WHERE is_active > 0"; |
||
| 33 | |||
| 34 | $stmt = $pdo->prepare( $sql ); |
||
| 35 | |||
| 36 | $stmt->setFetchMode( \PDO::FETCH_CLASS, $world ? get_class($world) : World::class ); |
||
| 37 | |||
| 38 | if (!$stmt->execute()): |
||
| 39 | throw new DatabaseException("Could not retrieve Worlds from database"); |
||
| 40 | endif; |
||
| 41 | |||
| 42 | $this->worlds = $stmt->fetchAll(\PDO::FETCH_UNIQUE); |
||
| 43 | } |
||
| 47 |