Conditions | 6 |
Paths | 4 |
Total Lines | 42 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 6.6563 |
Changes | 0 |
1 | <?php |
||
17 | 1 | public function __construct( \PDO $pdo, WebsiteAbstract $website = null, $table = null ) |
|
18 | { |
||
19 | 1 | $this->table = $table ?: $this->table; |
|
20 | |||
21 | // ID is listed twice here in order to use it with FETCH_UNIQUE as array key |
||
22 | $sql = "SELECT |
||
23 | id, |
||
24 | id, |
||
25 | title, |
||
26 | route, |
||
27 | content_file, |
||
28 | template, |
||
29 | dom_id, |
||
30 | javascripts, |
||
31 | stylesheets, |
||
32 | is_active |
||
33 | |||
34 | 1 | FROM {$this->table} |
|
35 | |||
36 | 1 | WHERE 1"; |
|
37 | |||
38 | 1 | $stmt = $pdo->prepare( $sql ); |
|
39 | |||
40 | 1 | $stmt->setFetchMode( \PDO::FETCH_CLASS, $website ? get_class($website) : Website::class ); |
|
41 | |||
42 | 1 | if (!$stmt->execute()): |
|
43 | throw new \RuntimeException("Could not retrieve Websites from database"); |
||
44 | endif; |
||
45 | |||
46 | 1 | $this->websites = array_map(function($row) { |
|
47 | // Cast numeric is_active field to integer |
||
48 | 1 | $row->is_active = (int) $row->is_active; |
|
49 | // Split into array |
||
50 | 1 | if (isset($row->javascripts)): |
|
51 | $row->javascripts = explode(",", $row->javascripts); |
||
52 | endif; |
||
53 | 1 | if (isset($row->stylesheets)): |
|
54 | $row->stylesheets = explode(",", $row->stylesheets); |
||
55 | endif; |
||
56 | 1 | return $row; |
|
57 | 1 | }, $stmt->fetchAll(\PDO::FETCH_UNIQUE)); |
|
58 | 1 | } |
|
59 | |||
62 |