diff --git a/.php_cs.php b/.php_cs.php new file mode 100644 index 0000000..ac524ce --- /dev/null +++ b/.php_cs.php @@ -0,0 +1,14 @@ +in('.') +; + +return PhpCsFixer\Config::create() + ->setRules([ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + ]) + ->setFinder($finder) + ->setUsingCache(false) +; \ No newline at end of file diff --git a/.phpstan.neon b/.phpstan.neon new file mode 100644 index 0000000..d634f04 --- /dev/null +++ b/.phpstan.neon @@ -0,0 +1,10 @@ +parameters: + ignoreErrors: + - '#Access to an undefined property PHPPM\\Bootstraps\\Symfony::\$.*#' + - '#invalid type AppKernel#' + - '#invalid typehint type AppKernel#' + - '#unknown class AppKernel#' + - '#unknown class Drupal.Core#' + - '#Instantiated class Drupal.Core#' + - '#PHPPM.Laravel.SessionGuard#' + - '#Property Illuminate.Auth.SessionGuard#' diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9e284ba --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +sudo: false + +language: php + +install: + - composer validate + - composer install + +matrix: + fast_finish: true + +jobs: + include: + - stage: lint + php: 7.1 + install: + - rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini + - composer require "phpstan/phpstan" "friendsofphp/php-cs-fixer:^2.8" + # dependencies for phpstan + - composer require --dev "symfony/symfony" "laravel/framework" "drupal/drupal" + script: + # Static analyzer check + - ./vendor/bin/phpstan analyze -c .phpstan.neon --level=4 --no-progress Bootstraps Bridges Laravel || true + # Check the code style + - IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS + - ./vendor/bin/php-cs-fixer fix --config=.php_cs.php -v --dry-run --diff --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}" + +# Cache package sources +cache: + directories: + - $HOME/.composer/cache diff --git a/Bootstraps/Drupal.php b/Bootstraps/Drupal.php index 0eaaeea..b737939 100644 --- a/Bootstraps/Drupal.php +++ b/Bootstraps/Drupal.php @@ -29,8 +29,8 @@ class Drupal implements BootstrapInterface, ApplicationEnvironmentAwareInterface /** * Instantiate the bootstrap, storing the $appenv * - * @param $appenv - * @param $debug + * @param string $appenv + * @param boolean $debug */ public function initialize($appenv, $debug) { diff --git a/Bootstraps/HooksInterface.php b/Bootstraps/HooksInterface.php index 332fa03..72b1a74 100644 --- a/Bootstraps/HooksInterface.php +++ b/Bootstraps/HooksInterface.php @@ -2,7 +2,8 @@ namespace PHPPM\Bootstraps; -interface HooksInterface { +interface HooksInterface +{ public function preHandle($app); public function postHandle($app); -} \ No newline at end of file +} diff --git a/Bootstraps/Laravel.php b/Bootstraps/Laravel.php index abfaec0..c8cd529 100644 --- a/Bootstraps/Laravel.php +++ b/Bootstraps/Laravel.php @@ -5,7 +5,10 @@ /** * A default bootstrap for the Laravel framework */ -class Laravel implements BootstrapInterface, HooksInterface, RequestClassProviderInterface, +class Laravel implements + BootstrapInterface, + HooksInterface, + RequestClassProviderInterface, ApplicationEnvironmentAwareInterface { /** @@ -21,7 +24,7 @@ class Laravel implements BootstrapInterface, HooksInterface, RequestClassProvide /** * Store the application * - * @var \Symfony\Component\HttpKernel\HttpKernelInterface + * @var \Illuminate\Foundation\Application|null */ protected $app; @@ -29,7 +32,7 @@ class Laravel implements BootstrapInterface, HooksInterface, RequestClassProvide * Instantiate the bootstrap, storing the $appenv * * @param string|null $appenv The environment your application will use to bootstrap (if any) - * @param $debug + * @param boolean $debug */ public function initialize($appenv, $debug) { @@ -42,7 +45,8 @@ public function initialize($appenv, $debug) /** * {@inheritdoc} */ - public function requestClass() { + public function requestClass() + { return '\Illuminate\Http\Request'; } @@ -53,7 +57,7 @@ public function getApplication() { if (file_exists('bootstrap/autoload.php')) { require_once 'bootstrap/autoload.php'; - } else if (file_exists('vendor/autoload.php')) { + } elseif (file_exists('vendor/autoload.php')) { require_once 'vendor/autoload.php'; } @@ -80,8 +84,8 @@ public function getApplication() $kernel = $this->app->make($isLaravel ? 'Illuminate\Contracts\Http\Kernel' : 'Laravel\Lumen\Application'); - $this->app->afterResolving('auth', function($auth) { - $auth->extend('session', function($app, $name, $config) { + $this->app->afterResolving('auth', function ($auth) { + $auth->extend('session', function ($app, $name, $config) { $provider = $app['auth']->createUserProvider($config['provider']); $guard = new \PHPPM\Laravel\SessionGuard($name, $provider, $app['session.store'], null, $app); if (method_exists($guard, 'setCookieJar')) { @@ -99,7 +103,7 @@ public function getApplication() }); $app = $this->app; - $this->app->extend('session.store', function() use ($app) { + $this->app->extend('session.store', function () use ($app) { $manager = $app['session']; return $manager->driver(); }); @@ -119,7 +123,7 @@ public function preHandle($app) * @param \Illuminate\Contracts\Foundation\Application $app */ public function postHandle($app) - { + { //check if this is a lumen framework, if so, do not reset //note that lumen does not have the getProvider method if (method_exists($this->app, 'getProvider')) { @@ -128,7 +132,6 @@ public function postHandle($app) $this->resetProvider('\Illuminate\Cookie\CookieServiceProvider'); $this->resetProvider('\Illuminate\Session\SessionServiceProvider'); } - } /** @@ -136,8 +139,7 @@ public function postHandle($app) */ protected function resetProvider($providerName) { - if (!$this->app->getProvider($providerName)) - { + if (!$this->app->getProvider($providerName)) { return; } diff --git a/Bootstraps/RequestClassProviderInterface.php b/Bootstraps/RequestClassProviderInterface.php index df3e3c6..710791c 100644 --- a/Bootstraps/RequestClassProviderInterface.php +++ b/Bootstraps/RequestClassProviderInterface.php @@ -8,4 +8,4 @@ interface RequestClassProviderInterface { public function requestClass(); -} \ No newline at end of file +} diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index 24ba8d6..1c10cdb 100644 --- a/Bootstraps/Symfony.php +++ b/Bootstraps/Symfony.php @@ -25,8 +25,8 @@ class Symfony implements BootstrapInterface, HooksInterface, ApplicationEnvironm /** * Instantiate the bootstrap, storing the $appenv * - * @param $appenv - * @param $debug + * @param string $appenv + * @param boolean $debug */ public function initialize($appenv, $debug) { @@ -59,11 +59,11 @@ public function getApplication() //since we need to change some services, we need to manually change some services $app = new $class($this->appenv, $this->debug); - // We need to change some services, before the boot, because they would - // otherwise be instantiated and passed to other classes which makes it + // We need to change some services, before the boot, because they would + // otherwise be instantiated and passed to other classes which makes it // impossible to replace them. - Utils::bindAndCall(function() use ($app) { + Utils::bindAndCall(function () use ($app) { // init bundles $app->initializeBundles(); @@ -71,7 +71,7 @@ public function getApplication() $app->initializeContainer(); }, $app); - Utils::bindAndCall(function() use ($app) { + Utils::bindAndCall(function () use ($app) { foreach ($app->getBundles() as $bundle) { $bundle->setContainer($app->container); $bundle->boot(); @@ -112,7 +112,7 @@ public function postHandle($app) //->Twig_Loader_Filesystem if ($container->has('twig.loader')) { $twigLoader = $container->get('twig.loader'); - Utils::bindAndCall(function() use ($twigLoader) { + Utils::bindAndCall(function () use ($twigLoader) { foreach ($twigLoader->cache as $path) { register_file($path); } @@ -138,7 +138,7 @@ public function postHandle($app) if ($profiler->has('db')) { Utils::bindAndCall(function () { //$logger: \Doctrine\DBAL\Logging\DebugStack - foreach ($this->loggers as $logger){ + foreach ($this->loggers as $logger) { Utils::hijackProperty($logger, 'queries', []); } }, $profiler->get('db'), null, 'Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector'); @@ -146,10 +146,10 @@ public function postHandle($app) //EventDataCollector if ($profiler->has('events')) { - Utils::hijackProperty($profiler->get('events'), 'data', array( - 'called_listeners' => array(), - 'not_called_listeners' => array(), - )); + Utils::hijackProperty($profiler->get('events'), 'data', [ + 'called_listeners' => [], + 'not_called_listeners' => [], + ]); } //TwigDataCollector @@ -190,6 +190,5 @@ public function postHandle($app) $logger->clear(); } } - } } diff --git a/Bridges/HttpKernel.php b/Bridges/HttpKernel.php index 1177792..e5c4be6 100644 --- a/Bridges/HttpKernel.php +++ b/Bridges/HttpKernel.php @@ -18,7 +18,6 @@ use Symfony\Component\HttpKernel\TerminableInterface; use Illuminate\Contracts\Http\Kernel; - class HttpKernel implements BridgeInterface { /** @@ -150,11 +149,11 @@ protected function mapRequest(ServerRequestInterface $psrRequest) /** @var \React\Http\Io\UploadedFile $file */ $uploadedFiles = $psrRequest->getUploadedFiles(); - $mapFiles = function(&$files) use (&$mapFiles) { + $mapFiles = function (&$files) use (&$mapFiles) { foreach ($files as &$file) { if (is_array($file)) { $mapFiles($file); - } else if ($file instanceof UploadedFileInterface) { + } elseif ($file instanceof UploadedFileInterface) { $tmpname = tempnam(sys_get_temp_dir(), 'upload'); $this->tempFiles[] = $tmpname; @@ -180,12 +179,11 @@ protected function mapRequest(ServerRequestInterface $psrRequest) // @todo check howto handle additional headers // @todo check howto support other HTTP methods with bodies - $post = $psrRequest->getParsedBody() ?: array(); + $post = $psrRequest->getParsedBody() ?: []; if ($this->bootstrap instanceof RequestClassProviderInterface) { $class = $this->bootstrap->requestClass(); - } - else { + } else { $class = SymfonyRequest::class; } @@ -289,8 +287,7 @@ protected function mapResponse(SymfonyResponse $syResponse, $stdout='') if ($syResponse instanceof SymfonyStreamedResponse) { $syResponse->sendContent(); $content = @ob_get_clean(); - } - else { + } else { $content = $syResponse->getContent(); @ob_end_flush(); } @@ -315,7 +312,7 @@ protected function mapResponse(SymfonyResponse $syResponse, $stdout='') } /** - * @param $appBootstrap + * @param string $appBootstrap * @return string * @throws \RuntimeException */ diff --git a/Laravel/SessionGuard.php b/Laravel/SessionGuard.php index 2b4eb1e..ccdf17e 100644 --- a/Laravel/SessionGuard.php +++ b/Laravel/SessionGuard.php @@ -24,15 +24,16 @@ class SessionGuard extends \Illuminate\Auth\SessionGuard * @param \Illuminate\Contracts\Auth\UserProvider $provider * @param \Illuminate\Contracts\Session\Session $session * @param \Symfony\Component\HttpFoundation\Request $request - * @param mixed|\Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app * @return void */ - public function __construct($name, + public function __construct( + $name, UserProvider $provider, Session $session, Request $request = null, - Application $app) - { + Application $app + ) { $this->name = $name; $this->session = $session; $this->request = $request;