Skip to content

Commit

Permalink
updated codestyle rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Chernyi committed Mar 28, 2018
1 parent f93a533 commit df80a97
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 31 deletions.
7 changes: 4 additions & 3 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ $finder = \PhpCsFixer\Finder::create()
return \PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules(array(
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PSR1' => true,
'@PSR2' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'list_syntax' => ['syntax' => 'short'],
'no_short_echo_tag' => true,
'native_function_invocation' => true,
'no_extra_consecutive_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
'no_null_property_initialization' => true,
'no_short_echo_tag' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/Repository/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function login(string $login, string $password): ?Root
return null;
}

if (!password_verify($password, $user->get($this->getPasswordField()))) {
if (!\password_verify($password, $user->get($this->getPasswordField()))) {
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Auth/Storage/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Cookie extends Root implements StorageInterface
public function setUser(Root $user)
{
//@codeCoverageIgnoreStart
if (!class_exists(\Dflydev\FigCookies\Cookie::class)) {
if (!\class_exists(\Dflydev\FigCookies\Cookie::class)) {
throw new \Exception('wtf/auth cookie storage requires dflydev/fig-cookies package installed');
}
//@codeCoverageIgnoreEnd
Expand All @@ -28,7 +28,7 @@ public function setUser(Root $user)
public function getUser(): ?Root
{
//@codeCoverageIgnoreStart
if (!class_exists(\Dflydev\FigCookies\Cookie::class)) {
if (!\class_exists(\Dflydev\FigCookies\Cookie::class)) {
throw new \Exception('wtf/auth cookie storage requires dflydev/fig-cookies package installed');
}
//@codeCoverageIgnoreEnd
Expand All @@ -49,7 +49,7 @@ public function getUser(): ?Root
public function isLoggedIn(): bool
{
//@codeCoverageIgnoreStart
if (!class_exists(\Dflydev\FigCookies\Cookie::class)) {
if (!\class_exists(\Dflydev\FigCookies\Cookie::class)) {
throw new \Exception('wtf/auth cookie storage requires dflydev/fig-cookies package installed');
}
//@codeCoverageIgnoreEnd
Expand Down
20 changes: 10 additions & 10 deletions src/Auth/Storage/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JWT extends Root implements StorageInterface
public function setUser(Root $user)
{
//@codeCoverageIgnoreStart
if (!class_exists(\Firebase\JWT\JWT::class)) {
if (!\class_exists(\Firebase\JWT\JWT::class)) {
throw new \Exception('wtf/auth jwt storage requires wtf/rest or firebase/php-jwt packages installed');
}
//@codeCoverageIgnoreEnd
Expand All @@ -24,14 +24,14 @@ public function setUser(Root $user)
}

return \Firebase\JWT\JWT::encode([
'jti' => $user->getId().time().random_int(PHP_INT_MIN, PHP_INT_MAX),
'iat' => $this->config('jwt.iat', time()),
'nbf' => $this->config('jwt.nbf', time()),
'iss' => $this->config('jwt.iss', getenv('APP_HOST')),
'aud' => $this->config('jwt.aud', getenv('APP_HOST')),
'exp' => $this->config('jwt.exp', time() + 604800),
'jti' => $user->getId().\time().\random_int(PHP_INT_MIN, PHP_INT_MAX),
'iat' => $this->config('jwt.iat', \time()),
'nbf' => $this->config('jwt.nbf', \time()),
'iss' => $this->config('jwt.iss', \getenv('APP_HOST')),
'aud' => $this->config('jwt.aud', \getenv('APP_HOST')),
'exp' => $this->config('jwt.exp', \time() + 604800),
'data' => $data,
], getenv('APP_SECRET'), $this->config('jwt.algorithm', ['HS256'])[0]);
], \getenv('APP_SECRET'), $this->config('jwt.algorithm', ['HS256'])[0]);
}

/**
Expand All @@ -40,7 +40,7 @@ public function setUser(Root $user)
public function getUser(): ?Root
{
//@codeCoverageIgnoreStart
if (!class_exists(\Firebase\JWT\JWT::class)) {
if (!\class_exists(\Firebase\JWT\JWT::class)) {
throw new \Exception('wtf/auth jwt storage requires wtf/rest or firebase/php-jwt packages installed');
}
//@codeCoverageIgnoreEnd
Expand All @@ -52,7 +52,7 @@ public function getUser(): ?Root

// tuupola/slim-jwt-auth implementation
if ($token = $this->request->getAttribute($this->config('jwt.attribute', 'token'))) {
$data = (array) (is_object($token) && property_exists($token, 'data') ? $token->data : ($token['data'] ?? $token));
$data = (array) (\is_object($token) && \property_exists($token, 'data') ? $token->data : ($token['data'] ?? $token));

return $this->entity($this->config('auth.entity'))->setData($data);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Auth/Storage/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Session extends Root implements StorageInterface
*/
public function setUser(Root $user)
{
if (PHP_SESSION_ACTIVE !== session_status()) {
if (PHP_SESSION_ACTIVE !== \session_status()) {
throw new \Exception('Session not started');
}

Expand All @@ -30,7 +30,7 @@ public function setUser(Root $user)
*/
public function getUser(): ?Root
{
if (PHP_SESSION_ACTIVE !== session_status()) {
if (PHP_SESSION_ACTIVE !== \session_status()) {
return null;
}

Expand All @@ -46,7 +46,7 @@ public function getUser(): ?Root
*/
public function isLoggedIn(): bool
{
if (PHP_SESSION_ACTIVE !== session_status()) {
if (PHP_SESSION_ACTIVE !== \session_status()) {
return false;
}

Expand All @@ -59,8 +59,8 @@ public function isLoggedIn(): bool
public function logout(): void
{
$_SESSION = [];
if (PHP_SESSION_ACTIVE === session_status()) {
session_destroy();
if (PHP_SESSION_ACTIVE === \session_status()) {
\session_destroy();
}
}
}
10 changes: 5 additions & 5 deletions tests/Auth/Storage/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testLoginWithoutSession(): void
*/
public function testLoggedIn(): void
{
session_start();
\session_start();
$this->assertFalse($this->app->getContainer()->auth->isLoggedIn());
}

Expand All @@ -59,7 +59,7 @@ public function testLoggedIn(): void
*/
public function testGetUserNull(): void
{
session_start();
\session_start();
$this->assertNull($this->app->getContainer()->auth->getUser());
}

Expand All @@ -68,7 +68,7 @@ public function testGetUserNull(): void
*/
public function testGetUser(): void
{
session_start();
\session_start();
$_SESSION['user'] = ['login' => 'login'];

$this->assertInstanceOf('\Wtf\Root', $this->app->getContainer()->auth->getUser());
Expand All @@ -80,7 +80,7 @@ public function testGetUser(): void
*/
public function testLogin(): void
{
session_start();
\session_start();
$this->assertNull($this->app->getContainer()->auth->login('notexist', 'password'));
$this->assertNull($this->app->getContainer()->auth->login('login', 'wrongpassword'));
$this->assertInstanceOf('\Wtf\Root', $this->app->getContainer()->auth->login('login', 'me'));
Expand All @@ -91,7 +91,7 @@ public function testLogin(): void
*/
public function testLogout(): void
{
session_start();
\session_start();
$this->app->getContainer()->auth->login('login', 'me');
$this->assertInstanceOf('\Wtf\Root', $this->app->getContainer()->auth->getUser());
$this->app->getContainer()->auth->logout();
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Enable Composer autoloader
/** @var \Composer\Autoload\ClassLoader $autoloader */
$autoloader = require dirname(__DIR__).'/vendor/autoload.php';
$autoloader = require \dirname(__DIR__).'/vendor/autoload.php';

// Register test classes
$autoloader->addPsr4('Wtf\\Auth\\Tests\\', __DIR__);
Expand Down
6 changes: 3 additions & 3 deletions tests/data/dummy/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Dummy extends \Wtf\Root

public function setData($data)
{
$this->data = array_merge($this->data, $data);
$this->data = \array_merge($this->data, $data);

return $this;
}
Expand All @@ -32,8 +32,8 @@ public function load($value, $field = 'id', $fields = '*')
public function has($where)
{
if (
('login' === array_keys($where)[0] && 'login' === $where['login'])
|| ('id' === array_keys($where)[0] && '1' === $where['id'])
('login' === \array_keys($where)[0] && 'login' === $where['login'])
|| ('id' === \array_keys($where)[0] && '1' === $where['id'])
) {
return true;
}
Expand Down

0 comments on commit df80a97

Please sign in to comment.