diff --git a/.travis.yml b/.travis.yml index 43c20ef..e211c37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ before_script: script: - vendor/bin/phpunit --coverage-clover=coverage.xml + - composer phpstan after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index da27dc1..1823a09 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,10 @@ npm run serve Once everything is ready visit: ```http://localhost:8080``` -### Run tests +### Run tests & static analysis ``` vendor/bin/phpunit +composer phpstan ``` ### Deployment diff --git a/backend/Controllers/AuthController.php b/backend/Controllers/AuthController.php index de248a5..dd4b0e2 100644 --- a/backend/Controllers/AuthController.php +++ b/backend/Controllers/AuthController.php @@ -67,6 +67,10 @@ class AuthController return $response->json($errors->firstOfAll(), 422); } + if ($auth->user() === null) { + return $response->json(['oldpassword' => 'Wrong password'], 422); + } + if (! $auth->authenticate($auth->user()->getUsername(), $request->input('oldpassword'))) { return $response->json(['oldpassword' => 'Wrong password'], 422); } diff --git a/backend/Services/Auth/Adapters/Database.php b/backend/Services/Auth/Adapters/Database.php index fcb5471..d9a716e 100644 --- a/backend/Services/Auth/Adapters/Database.php +++ b/backend/Services/Auth/Adapters/Database.php @@ -101,7 +101,7 @@ class Database implements Service, AuthInterface ], 'WHERE username = ?', $username); } - return $this->find($user->getUsername()); + return $this->find($user->getUsername()) ?: $user; } public function add(User $user, $password): User @@ -119,7 +119,7 @@ class Database implements Service, AuthInterface 'password' => $this->hashPassword($password), ]); - return $this->find($user->getUsername()); + return $this->find($user->getUsername()) ?: $user; } public function delete(User $user) diff --git a/backend/Services/Auth/Adapters/JsonFile.php b/backend/Services/Auth/Adapters/JsonFile.php index 381ec00..0bc4510 100644 --- a/backend/Services/Auth/Adapters/JsonFile.php +++ b/backend/Services/Auth/Adapters/JsonFile.php @@ -96,7 +96,7 @@ class JsonFile implements Service, AuthInterface $this->saveUsers($all_users); - return $this->find($user->getUsername()); + return $this->find($user->getUsername()) ?: $user; } } @@ -122,7 +122,7 @@ class JsonFile implements Service, AuthInterface $this->saveUsers($all_users); - return $this->find($user->getUsername()); + return $this->find($user->getUsername()) ?: $user; } public function delete(User $user) diff --git a/backend/Services/Session/Adapters/SessionStorage.php b/backend/Services/Session/Adapters/SessionStorage.php index 9bb0a65..34c1256 100644 --- a/backend/Services/Session/Adapters/SessionStorage.php +++ b/backend/Services/Session/Adapters/SessionStorage.php @@ -55,7 +55,11 @@ class SessionStorage implements Service, SessionStorageInterface public function invalidate() { - if ($this->getSession() !== null || ! $this->getSession()->isStarted()) { + if ($this->getSession() === null) { + return; + } + + if (! $this->getSession()->isStarted()) { $this->getSession()->start(); } diff --git a/backend/Services/Storage/Filesystem.php b/backend/Services/Storage/Filesystem.php index 48f01f4..aa6526b 100644 --- a/backend/Services/Storage/Filesystem.php +++ b/backend/Services/Storage/Filesystem.php @@ -282,6 +282,6 @@ class Filesystem implements Service $tmp = explode($this->separator, trim($path, $this->separator)); - return array_pop($tmp); + return (string) array_pop($tmp); } } diff --git a/composer.json b/composer.json index 5f0b60b..79b0875 100644 --- a/composer.json +++ b/composer.json @@ -36,5 +36,8 @@ "symfony/var-dumper": "^4.2", "league/flysystem-memory": "^1.0", "phpstan/phpstan": "^0.11.8" + }, + "scripts": { + "phpstan": "phpstan analyse ./backend --level=7" } }