|
1 | 1 | <?php namespace Tatter\Visits; |
2 | 2 |
|
3 | | -/*** |
4 | | -* Name: Visits |
5 | | -* Author: Matthew Gatner |
6 | | -* Contact: mgatner@tattersoftware.com |
7 | | -* Created: 2019-02-12 |
8 | | -* |
9 | | -* Description: Lightweight traffic tracking for CodeIgniter 4 |
10 | | -* |
11 | | -* Requirements: |
12 | | -* >= PHP 7.1 |
13 | | -* >= CodeIgniter 4.0 |
14 | | -* Preconfigured, autoloaded Database |
15 | | -* CodeIgniter's URL helper (loaded automatically) |
16 | | -* Visits table (run migrations) |
17 | | -* |
18 | | -* Configuration: |
19 | | -* Use app/Config/Visits.php to override default behavior |
20 | | -* Run migrations to update database tables: |
21 | | -* > php spark migrate:latest -n "Tatter\Visits" |
22 | | -* |
23 | | -* @package CodeIgniter4-Visits |
24 | | -* @author Matthew Gatner |
25 | | -* @link https://github.com/tattersoftware/codeigniter4-visits |
26 | | -***/ |
27 | | - |
28 | 3 | use CodeIgniter\Config\BaseConfig; |
29 | 4 | use CodeIgniter\Config\Services; |
30 | 5 | use CodeIgniter\Database\ConnectionInterface; |
|
33 | 8 | use Tatter\Visits\Models\VisitModel; |
34 | 9 | use Tatter\Visits\Exceptions\VisitsException; |
35 | 10 |
|
36 | | -/*** |
37 | | - * CLASS |
38 | | - ***/ |
39 | 11 | class Visits |
40 | 12 | { |
41 | 13 | /** |
@@ -77,11 +49,14 @@ public function __construct(VisitsConfig $config, $db = null) |
77 | 49 | // If no db connection passed in, use the default database group. |
78 | 50 | $this->db = db_connect($db); |
79 | 51 |
|
80 | | - // validations |
81 | | - $visits = new VisitModel(); |
82 | | - if (! $this->db->tableExists($visits->table)) |
| 52 | + /** |
| 53 | + * @phpstan-ignore-next-line |
| 54 | + * @psalm-suppress InaccessibleProperty |
| 55 | + */ |
| 56 | + $table = model(VisitModel::class)->table; |
| 57 | + if (! $this->db->tableExists($table)) |
83 | 58 | { |
84 | | - throw VisitsException::forMissingDatabaseTable($visits->table); |
| 59 | + throw VisitsException::forMissingDatabaseTable($table); |
85 | 60 | } |
86 | 61 |
|
87 | 62 | if (empty($this->config->trackingMethod)) |
|
0 commit comments