| Conditions | 3 |
| Paths | 3 |
| Total Lines | 25 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 3.009 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 39 | 2 | public function auth(string $login, string $password): array |
|
| 40 | { |
||
| 41 | 2 | $repo = (new Users($this->container))->getByEmail($login); |
|
| 42 | 2 | $dbc = new Core($this->container); |
|
| 43 | $dbc |
||
| 44 | 2 | ->fromOrm($repo) |
|
| 45 | 2 | ->run($repo->getSql(), $repo->getBuilderValues()) |
|
| 46 | 2 | ->hydrate(); |
|
| 47 | 2 | $result = $dbc->getRowset(); |
|
| 48 | 2 | if (empty($result)) { |
|
| 49 | 1 | unset($repo, $dbc, $result); |
|
| 50 | 1 | return []; |
|
| 51 | } |
||
| 52 | 1 | $user = $result[0]; |
|
| 53 | 1 | $config = $this->container->getService(Config::class); |
|
| 54 | 1 | $clearPassword = (new Crypt($config))->decrypt( |
|
| 55 | 1 | $user[self::_PASSWORD], |
|
| 56 | 1 | true |
|
| 57 | ); |
||
| 58 | 1 | if ($password == $clearPassword) { |
|
| 59 | 1 | unset($config, $repo, $dbc, $result); |
|
| 60 | 1 | return $user; |
|
| 61 | } |
||
| 62 | unset($config, $repo, $dbc, $result); |
||
| 63 | return []; |
||
| 64 | } |
||
| 66 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: