Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
migrated more to php7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
brainexe committed Mar 15, 2017
1 parent 2aa4c0b commit d2f1f39
Show file tree
Hide file tree
Showing 68 changed files with 79 additions and 114 deletions.
4 changes: 2 additions & 2 deletions Tests/BrainExe/Core/Middleware/SecurityTest.php
Expand Up @@ -40,7 +40,7 @@ public function testProcessResponse()

$this->subject->processResponse($request, $response);

$expectedCSP = "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'; connect-src 'self' 'self' socket.localhost:8080";
$expectedCSP = "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'; connect-src 'self' socket.localhost:8080";
$this->assertEquals($expectedCSP, $response->headers->get('Content-Security-Policy'));
$this->assertTrue($response->headers->has('X-Frame-Options'));
$this->assertTrue($response->headers->has('Strict-Transport-Security'));
Expand All @@ -58,7 +58,7 @@ public function testProcessResponseRelativeSocketServer()

$this->subject->processResponse($request, $response);

$expectedCSP = "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'; connect-src 'self' 'self' my.host.de";
$expectedCSP = "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'; connect-src 'self' my.host.de";
$this->assertEquals($expectedCSP, $response->headers->get('Content-Security-Policy'));
}

Expand Down
2 changes: 1 addition & 1 deletion container.xml
Expand Up @@ -113,7 +113,7 @@
<argument>cache:%application.name%</argument>
</call>
</service>
<service id="Cache" class="Symfony\Component\Cache\Adapte" public="false">
<service id="Cache" class="Symfony\Component\Cache\Adapter" public="false">
<argument type="service" id="redis"/>
<argument>cache</argument>
</service>
Expand Down
1 change: 0 additions & 1 deletion src/AnnotationLoader.php
Expand Up @@ -13,7 +13,6 @@
use SplFileInfo;
use Symfony\Component\Config\Loader\Loader as ConfigLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class AnnotationLoader extends ConfigLoader
{
Expand Down
1 change: 0 additions & 1 deletion src/Annotations/Builder/Command.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Annotations\Builder;

use BrainExe\Core\Annotations\Builder\ServiceDefinition;
use BrainExe\Core\DependencyInjection\CompilerPass\ConsoleCompilerPass;
use Symfony\Component\DependencyInjection\Definition;

Expand Down
1 change: 0 additions & 1 deletion src/Annotations/Builder/CompilerPass.php
Expand Up @@ -3,7 +3,6 @@
namespace BrainExe\Core\Annotations\Builder;

use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Annotations\Builder\ServiceDefinition;
use BrainExe\Core\Annotations\CompilerPass as CompilerPassAnnotation;
use Exception;
use ReflectionClass;
Expand Down
3 changes: 1 addition & 2 deletions src/Annotations/Builder/Controller.php
Expand Up @@ -3,7 +3,6 @@
namespace BrainExe\Core\Annotations\Builder;

use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Annotations\Builder\ServiceDefinition;
use BrainExe\Core\Annotations\Guest;
use BrainExe\Core\Annotations\Role;
use BrainExe\Core\Annotations\Route;
Expand All @@ -25,7 +24,7 @@ class Controller extends ServiceDefinition
public function build(ReflectionClass $reflectionClass, Service $annotation, Definition $definition)
{
/** @var Definition $definition */
list ($serviceId, $definition) = parent::build(
[, $definition] = parent::build(
$reflectionClass,
$annotation,
$definition
Expand Down
1 change: 0 additions & 1 deletion src/Annotations/Builder/EventListener.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Annotations\Builder;

use BrainExe\Core\Annotations\Builder\ServiceDefinition;
use BrainExe\Core\Annotations\Listen;
use BrainExe\Core\DependencyInjection\CompilerPass\EventListenerCompilerPass;
use ReflectionMethod;
Expand Down
1 change: 0 additions & 1 deletion src/Annotations/Builder/Middleware.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Annotations\Builder;

use BrainExe\Core\Annotations\Builder\ServiceDefinition;
use BrainExe\Core\DependencyInjection\CompilerPass\MiddlewareCompilerPass;
use Symfony\Component\DependencyInjection\Definition;

Expand Down
1 change: 1 addition & 0 deletions src/Annotations/Builder/ServiceDefinition.php
Expand Up @@ -63,6 +63,7 @@ public function build(ReflectionClass $reflectionClass, Service $annotation, Def

/**
* @param Definition $definition
* @param string $serviceId
* @return string null
*/
public function setupDefinition(Definition $definition, string $serviceId)
Expand Down
1 change: 0 additions & 1 deletion src/Annotations/Command.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Annotations;

use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Annotations\Builder\Command as Builder;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\Reader;
Expand Down
1 change: 0 additions & 1 deletion src/Annotations/Controller.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Annotations;

use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Annotations\Builder\Controller as Builder;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\Reader;
Expand Down
1 change: 0 additions & 1 deletion src/Annotations/EventListener.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Annotations;

use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Annotations\Builder\EventListener as Builder;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\Reader;
Expand Down
8 changes: 2 additions & 6 deletions src/Annotations/Listen.php
Expand Up @@ -22,16 +22,12 @@ class Listen
public $priority;

/**
* @param string $event
* @param string|array $event
* @param int|null $priority
*/
public function __construct($event, $priority = null)
{
if (is_array($event)) {
$this->event = $event['value'];
} else {
$this->event = $event;
}
$this->event = is_array($event) ? $event['value'] : $event;
$this->priority = $priority;
}
}
1 change: 0 additions & 1 deletion src/Annotations/Middleware.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Annotations;

use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Annotations\Builder\Middleware as Builder;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\Reader;
Expand Down
1 change: 0 additions & 1 deletion src/Application/AppKernel.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Application;

use BrainExe\Core\Annotations\Inject;
use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Middleware\MiddlewareInterface;
use Iterator;
Expand Down
15 changes: 11 additions & 4 deletions src/Application/SerializedRouteCollection.php
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\Routing\RouteCollection;

/**
* @Service("Core.RouteCollection", shared=false)
* @Service(shared=false)
*/
class SerializedRouteCollection extends RouteCollection
{
Expand All @@ -22,7 +22,7 @@ class SerializedRouteCollection extends RouteCollection
/**
* @var string[]
*/
private $serializedRoutes = null;
private $serializedRoutes;

/**
* @var Route[]
Expand All @@ -32,6 +32,7 @@ class SerializedRouteCollection extends RouteCollection
/**
* @param string $name
* @return Route
* @throws InvalidArgumentException
*/
public function get($name)
{
Expand All @@ -45,7 +46,12 @@ public function get($name)
throw new InvalidArgumentException(sprintf('invalid route: %s', $name));
}

return $this->cache[$name] = unserialize($this->serializedRoutes[$name]);
return $this->cache[$name] = unserialize(
$this->serializedRoutes[$name],
[
'allowed_classes' => [Route::class]
]
);
}

public function all()
Expand Down Expand Up @@ -94,6 +100,7 @@ public function add($name, Route $route)

/**
* @param array|string $name
* @throws RuntimeException
*/
public function remove($name)
{
Expand All @@ -110,7 +117,7 @@ private function initAll()

private function loadFromCache()
{
if ($this->serializedRoutes == null) {
if (null === $this->serializedRoutes) {
$this->serializedRoutes = $this->includeFile(self::CACHE_FILE);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Authentication/Command/CreateToken.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Authentication\Command;

use BrainExe\Core\Annotations\Inject;
use BrainExe\Core\Annotations\Command as CommandAnnotation;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -11,7 +10,7 @@
use BrainExe\Core\Authentication\Token as TokenModel;

/**
* @CommandAnnotation("Authentication.Command.CreateToken")
* @CommandAnnotation
*/
class CreateToken extends Command
{
Expand Down
3 changes: 1 addition & 2 deletions src/Authentication/Command/ListTokens.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Authentication\Command;

use BrainExe\Core\Annotations\Inject;
use BrainExe\Core\Annotations\Command as CommandAnnotation;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
Expand All @@ -12,7 +11,7 @@
use BrainExe\Core\Authentication\Token as TokenModel;

/**
* @CommandAnnotation("Authentication.Command.ListTokens")
* @CommandAnnotation
*/
class ListTokens extends Command
{
Expand Down
5 changes: 0 additions & 5 deletions src/Authentication/Controller/PasswordController.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Authentication\Controller;

use BrainExe\Core\Annotations\Inject;
use BrainExe\Core\Annotations\Controller;
use BrainExe\Core\Annotations\Route;
use BrainExe\Core\Application\UserException;
Expand All @@ -27,10 +26,6 @@ class PasswordController
private $passwordHasher;

/**
* @Inject({
* "@Core.Authentication.UserProvider",
* "@Core.Authentication.PasswordHasher"
* })
* @param UserProvider $userProvider
* @param PasswordHasher $passwordHasher
*/
Expand Down
1 change: 0 additions & 1 deletion src/Authentication/Controller/RegisterController.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Authentication\Controller;


use BrainExe\Core\Annotations\Controller;
use BrainExe\Core\Annotations\Guest;
use BrainExe\Core\Annotations\Route;
Expand Down
1 change: 0 additions & 1 deletion src/Authentication/Controller/TokenController.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Authentication\Controller;

use BrainExe\Core\Annotations\Inject;
use BrainExe\Core\Annotations\Controller;
use BrainExe\Core\Annotations\Route;
use BrainExe\Core\Authentication\Token;
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Controller/UserController.php
Expand Up @@ -60,7 +60,7 @@ public function getAvatars() : array
*/
public function setAvatars(Request $request, $avatar) : UserVO
{
if (!in_array($avatar, UserVO::AVATARS)) {
if (!in_array($avatar, UserVO::AVATARS, true)) {
throw new UserException($this->translate('Invalid avatar: %s', $avatar));
}

Expand Down
4 changes: 1 addition & 3 deletions src/Authentication/Login.php
Expand Up @@ -2,7 +2,6 @@

namespace BrainExe\Core\Authentication;

use BrainExe\Core\Annotations\Inject;
use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Application\UserException;
use BrainExe\Core\Authentication\Event\AuthenticateUserEvent;
Expand Down Expand Up @@ -92,7 +91,7 @@ public function loginWithToken(string $token, SessionInterface $session) : UserV
{
$tokenData = $this->token->getToken($token);

if (empty($tokenData) || !in_array(self::TOKEN_LOGIN, $tokenData['roles'])) {
if (empty($tokenData) || !in_array(self::TOKEN_LOGIN, $tokenData['roles'], true)) {
throw new UserException('Invalid Token');
}

Expand Down Expand Up @@ -124,7 +123,6 @@ public function needsOneTimeToken(string $username) : bool
* @param SessionInterface $session
* @param AuthenticationDataVO $authenticationVo
* @param UserVO $userVo
* @return AuthenticateUserEvent
*/
private function handleLogin(
SessionInterface $session,
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/PasswordHasher.php
Expand Up @@ -6,7 +6,7 @@
use BrainExe\Core\Annotations\Service;

/**
* @Service("Core.Authentication.PasswordHasher")
* @Service
*/
class PasswordHasher
{
Expand Down
4 changes: 3 additions & 1 deletion src/Authentication/Register.php
Expand Up @@ -31,7 +31,9 @@ class Register
private $registrationEnabled;

/**
* @Inject({"@Core.Authentication.UserProvider", "@RegisterTokens", "%application.registration_enabled%"})
* @Inject({
* "registrationEnabled" = "%application.registration_enabled%"
* })
* @param UserProvider $userProvider
* @param RegisterTokens $tokens
* @param bool $registrationEnabled
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/RegisterTokens.php
Expand Up @@ -7,7 +7,7 @@
use BrainExe\Core\Traits\RedisTrait;

/**
* @Service("RegisterTokens")
* @Service
*/
class RegisterTokens
{
Expand Down
4 changes: 2 additions & 2 deletions src/Authentication/TOTP/OneTimePassword.php
Expand Up @@ -94,11 +94,11 @@ public function getData($secret)
public function verifyOneTimePassword(UserVO $userVo, $givenToken)
{
if (empty($userVo->one_time_secret)) {
throw new UserException(_("No one time secret requested"));
throw new UserException(_('No one time secret requested'));
}

if (empty($givenToken)) {
throw new UserException(_("No one time token given"));
throw new UserException(_('No one time token given'));
}

$verified = $this->totp->verify($userVo->one_time_secret, $givenToken);
Expand Down
6 changes: 3 additions & 3 deletions src/Authentication/TOTP/TOTP.php
Expand Up @@ -105,11 +105,11 @@ public function getUri(string $secret) : string
$opt['secret'] = trim(Base32::encode($secret), '=');
$opt['period'] = $this->interval;

ksort($opt);
ksort($opt, SORT_STRING);

$params = str_replace(['+', '%7E'], ['%20', '~'], http_build_query($opt));

return "otpauth://totp/" . rawurlencode($this->label) . "?$params";
return 'otpauth://totp/' . rawurlencode($this->label) . "?$params";
}

/**
Expand Down Expand Up @@ -151,7 +151,7 @@ private function generateOTP($input, $secret)
*/
private function timecode($timestamp)
{
return (int)((((int)$timestamp * 1000) / ($this->interval * 1000)));
return (int)(((int)$timestamp * 1000) / ($this->interval * 1000));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Authentication/Token.php
Expand Up @@ -75,14 +75,14 @@ public function getTokensForUser(int $userId)
* @param string|null $role
* @return int|null
*/
public function hasUserForRole(string $token, string $role = null)
public function hasUserForRole(string $token, string $role = null) : ?int
{
$tokenData = $this->getToken($token);
if (empty($tokenData)) {
return null;
}

if ($role && !in_array($role, $tokenData['roles'])) {
if ($role && !in_array($role, $tokenData['roles'], true)) {
return null;
}

Expand Down

0 comments on commit d2f1f39

Please sign in to comment.