diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 8f4dd5aa..00000000 --- a/.php_cs +++ /dev/null @@ -1,45 +0,0 @@ -in('src') - ->in('test') - ->notPath('TestAsset') - ->notPath('_files') - ->filter(function (SplFileInfo $file) { - if (strstr($file->getPath(), 'compatibility')) { - return false; - } - }); -$config = Symfony\CS\Config\Config::create(); -$config->level(null); -$config->fixers( - array( - 'braces', - 'duplicate_semicolon', - 'elseif', - 'empty_return', - 'encoding', - 'eof_ending', - 'function_call_space', - 'function_declaration', - 'indentation', - 'join_function', - 'line_after_namespace', - 'linefeed', - 'lowercase_keywords', - 'parenthesis', - 'multiple_use', - 'method_argument_space', - 'object_operator', - 'php_closing_tag', - 'remove_lines_between_uses', - 'short_array_syntax', - 'short_tag', - 'standardize_not_equal', - 'trailing_spaces', - 'unused_use', - 'visibility', - 'whitespacy_lines', - ) -); -$config->finder($finder); -return $config; diff --git a/.travis.yml b/.travis.yml index 90a549d7..4e5bf69d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,23 +25,22 @@ services: - mongodb matrix: - fast_finish: true include: - php: 5.5 env: - - EXECUTE_CS_CHECK=true + - CS_CHECK=true - php: 5.5 env: - EVENT_MANAGER_VERSION="^2.6.2" - SERVICE_MANAGER_VERSION="^2.7.5" - php: 5.6 env: - - EXECUTE_TEST_COVERALLS=true + - TEST_COVERAGE=true - DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)" - PATH="$HOME/.local/bin:$PATH" - php: 5.6 env: - - EXECUTE_TEST_COVERALLS=true + - TEST_COVERAGE=true - DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)" - PATH="$HOME/.local/bin:$PATH" - php: 5.6 @@ -61,15 +60,11 @@ matrix: allow_failures: - php: hhvm -notifications: - irc: "irc.freenode.org#zftalk.dev" - email: false - before_install: - pecl -q install mongodb - - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi + - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi - composer self-update - - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi - if [[ $EVENT_MANAGER_VERSION != '' ]]; then composer require --no-update "zendframework/zend-eventmanager:$EVENT_MANAGER_VERSION" ; fi - if [[ $EVENT_MANAGER_VERSION == '' ]]; then composer require --no-update "zendframework/zend-eventmanager:^3.0" ; fi - if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi @@ -79,13 +74,20 @@ install: - travis_retry composer install --no-interaction --ignore-platform-reqs script: - - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi - - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi - - if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi + - if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi - if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi after_success: - if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi after_script: - - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi + +notifications: + email: false + slack: + rooms: + - secure: "MlhbWQ2bxDu9dmQ7o2v/WwwAedl57SVVew0XN/Wvbnt1Q8DY+kBGVxmV7DzurOG0iiq7pzYySNgdyqKpE/2g1IhWD7txrT9BCSq0xPk4i+AUn4xMViZKCVkPYhaFo9K3Z1HnPJPfcnDz075umGKWhfip12LSIMkXRqkNANgKLZ3ouDFRRG1NL7bOmW8GDIAcF3TpIDCy9L+awnGMHTtSO6M1jtueksQpBH7ESosrtkferzNVeV2USvzZbzI04PQ9vsrOOZnkqXgNsk3+gMvZNw6PbCk3eOmgGyFaygpL1NXi3VV6sK6SFtwiuwAiEhiFudOnovpE/90HKtWyCISSSGMlUHF6trEVGR0tQxuw+Du1HNrBhiWZHj6vdMpNdZSEqwBEbCeO5LAHM9fKDIT2utQQXrk62julZCvnAupImgBl5IswlO6f/cGv8/cesLulyc9t6L0LCuuXG2xK/WPSCOtkFB4nuOgNNNXhkljyrYxi8poXGa+4SupqCMA0iNPeUB6NnyCMrBCbUnjEjNIGMezx7ELIoepJuw66py6smigYGyrVXhodlGPvr7jaXVjYHNbDadHA55Vk6tRgYwTZclnrSn8sU3jI3xW/a6APkwQMd40yc+GAy5F72jpONiXeB7f8UG+d4qoWH4doBJii+cb/tVroH1tFDlfTSa5XRec=" + on_success: change + on_failure: always diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7838e120..41de6625 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -77,24 +77,24 @@ To do so: ## Running Coding Standards Checks -This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding +This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding standards checks, and provides configuration for our selected checks. -`php-cs-fixer` is installed by default via Composer. +`phpcs` is installed by default via Composer. To run checks only: ```console -$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs +$ composer cs-check ``` -To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run` -flag: +`phpcs` also includes a tool for fixing most CS violations, `phpcbf`: + ```console -$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs +$ composer cs-fix ``` -If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure +If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure they pass, and make sure you add and commit the changes after verification. ## Recommended Workflow for Contributions diff --git a/composer.json b/composer.json index 2d433fcf..17ec1691 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,8 @@ "zendframework/zend-validator": "^2.6", "container-interop/container-interop": "^1.1", "mongodb/mongodb": "^1.0.1", - "fabpot/php-cs-fixer": "1.7.*", - "phpunit/PHPUnit": "~4.0" + "phpunit/PHPUnit": "~4.0", + "zendframework/zend-coding-standard": "~1.0.0" }, "suggest": { "zendframework/zend-cache": "Zend\\Cache component", @@ -52,5 +52,16 @@ "psr-4": { "ZendTest\\Session\\": "test/" } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "upload-coverage": "coveralls -v" } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..60162e2c --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,10 @@ + + + + + + src + test + + /src/ValidatorChain.php + diff --git a/src/AbstractContainer.php b/src/AbstractContainer.php index 504cd4d1..c4671eb1 100644 --- a/src/AbstractContainer.php +++ b/src/AbstractContainer.php @@ -63,7 +63,7 @@ abstract class AbstractContainer extends ArrayObject */ public function __construct($name = 'Default', Manager $manager = null) { - if (!preg_match('/^[a-z0-9][a-z0-9_\\\\]+$/i', $name)) { + if (! preg_match('/^[a-z0-9][a-z0-9_\\\\]+$/i', $name)) { throw new Exception\InvalidArgumentException( 'Name passed to container is invalid; must consist of alphanumerics, backslashes and underscores only' ); @@ -101,7 +101,7 @@ public static function getDefaultManager() { if (null === static::$defaultManager) { $manager = new static::$managerDefaultClass(); - if (!$manager instanceof Manager) { + if (! $manager instanceof Manager) { throw new Exception\InvalidArgumentException( 'Invalid default manager type provided; must implement ManagerInterface' ); @@ -133,7 +133,7 @@ protected function setManager(Manager $manager = null) { if (null === $manager) { $manager = static::getDefaultManager(); - if (!$manager instanceof Manager) { + if (! $manager instanceof Manager) { throw new Exception\InvalidArgumentException( 'Manager provided is invalid; must implement ManagerInterface' ); @@ -192,13 +192,13 @@ protected function verifyNamespace($createContainer = true) { $storage = $this->getStorage(); $name = $this->getName(); - if (!isset($storage[$name])) { - if (!$createContainer) { + if (! isset($storage[$name])) { + if (! $createContainer) { return; } $storage[$name] = $this->createContainer(); } - if (!is_array($storage[$name]) && !$storage[$name] instanceof Traversable) { + if (! is_array($storage[$name]) && ! $storage[$name] instanceof Traversable) { throw new Exception\RuntimeException('Container cannot write to storage due to type mismatch'); } @@ -219,7 +219,7 @@ protected function expireKeys($key = null) $name = $this->getName(); // Return early if key not found - if ((null !== $key) && !isset($storage[$name][$key])) { + if ((null !== $key) && ! isset($storage[$name][$key])) { return true; } @@ -407,13 +407,13 @@ public function offsetExists($key) $name = $this->getName(); // Return early if the key isn't set - if (!isset($storage[$name][$key])) { + if (! isset($storage[$name][$key])) { return false; } $expired = $this->expireKeys($key); - return !$expired; + return ! $expired; } /** @@ -424,7 +424,7 @@ public function offsetExists($key) */ public function offsetGet($key) { - if (!$this->offsetExists($key)) { + if (! $this->offsetExists($key)) { return; } $storage = $this->getStorage(); @@ -441,7 +441,7 @@ public function offsetGet($key) */ public function offsetUnset($key) { - if (!$this->offsetExists($key)) { + if (! $this->offsetExists($key)) { return; } $storage = $this->getStorage(); @@ -462,7 +462,7 @@ public function exchangeArray($input) if (is_object($input) && ($input instanceof ArrayObject || $input instanceof \ArrayObject)) { $input = $input->getArrayCopy(); } - if (!is_array($input)) { + if (! is_array($input)) { $input = (array) $input; } diff --git a/src/AbstractManager.php b/src/AbstractManager.php index 07b90026..47eabacf 100644 --- a/src/AbstractManager.php +++ b/src/AbstractManager.php @@ -70,7 +70,7 @@ public function __construct( ) { // init config if ($config === null) { - if (!class_exists($this->defaultConfigClass)) { + if (! class_exists($this->defaultConfigClass)) { throw new Exception\RuntimeException(sprintf( 'Unable to locate config class "%s"; class does not exist', $this->defaultConfigClass @@ -79,7 +79,7 @@ public function __construct( $config = new $this->defaultConfigClass(); - if (!$config instanceof Config) { + if (! $config instanceof Config) { throw new Exception\RuntimeException(sprintf( 'Default config class %s is invalid; must implement %s\Config\ConfigInterface', $this->defaultConfigClass, @@ -92,7 +92,7 @@ public function __construct( // init storage if ($storage === null) { - if (!class_exists($this->defaultStorageClass)) { + if (! class_exists($this->defaultStorageClass)) { throw new Exception\RuntimeException(sprintf( 'Unable to locate storage class "%s"; class does not exist', $this->defaultStorageClass @@ -101,7 +101,7 @@ public function __construct( $storage = new $this->defaultStorageClass(); - if (!$storage instanceof Storage) { + if (! $storage instanceof Storage) { throw new Exception\RuntimeException(sprintf( 'Default storage class %s is invalid; must implement %s\Storage\StorageInterface', $this->defaultConfigClass, diff --git a/src/Config/SessionConfig.php b/src/Config/SessionConfig.php index 8ed930d2..61e63eb5 100644 --- a/src/Config/SessionConfig.php +++ b/src/Config/SessionConfig.php @@ -196,7 +196,7 @@ public function setSerializeHandler($serializeHandler) public function setCacheLimiter($cacheLimiter) { $cacheLimiter = (string) $cacheLimiter; - if (!in_array($cacheLimiter, $this->validCacheLimiters)) { + if (! in_array($cacheLimiter, $this->validCacheLimiters)) { throw new Exception\InvalidArgumentException('Invalid cache limiter provided'); } $this->setOption('cache_limiter', $cacheLimiter); @@ -215,7 +215,7 @@ public function setHashFunction($hashFunction) { $hashFunction = (string) $hashFunction; $validHashFunctions = $this->getHashFunctions(); - if (!in_array($hashFunction, $validHashFunctions, true)) { + if (! in_array($hashFunction, $validHashFunctions, true)) { throw new Exception\InvalidArgumentException('Invalid hash function provided'); } @@ -233,8 +233,8 @@ public function setHashFunction($hashFunction) */ public function setHashBitsPerCharacter($hashBitsPerCharacter) { - if (!is_numeric($hashBitsPerCharacter) - || !in_array($hashBitsPerCharacter, $this->validHashBitsPerCharacters) + if (! is_numeric($hashBitsPerCharacter) + || ! in_array($hashBitsPerCharacter, $this->validHashBitsPerCharacters) ) { throw new Exception\InvalidArgumentException('Invalid hash bits per character provided'); } diff --git a/src/Config/StandardConfig.php b/src/Config/StandardConfig.php index 50bfb087..b4fa6d83 100644 --- a/src/Config/StandardConfig.php +++ b/src/Config/StandardConfig.php @@ -101,7 +101,7 @@ class StandardConfig implements ConfigInterface */ public function setOptions($options) { - if (!is_array($options) && !$options instanceof Traversable) { + if (! is_array($options) && ! $options instanceof Traversable) { throw new Exception\InvalidArgumentException(sprintf( 'Parameter provided to %s must be an array or Traversable', __METHOD__ @@ -225,10 +225,10 @@ public function getStorageOption($storageOption) */ public function setSavePath($savePath) { - if (!is_dir($savePath)) { + if (! is_dir($savePath)) { throw new Exception\InvalidArgumentException('Invalid save_path provided; not a directory'); } - if (!is_writable($savePath)) { + if (! is_writable($savePath)) { throw new Exception\InvalidArgumentException('Invalid save_path provided; not writable'); } @@ -289,7 +289,7 @@ public function getName() */ public function setGcProbability($gcProbability) { - if (!is_numeric($gcProbability)) { + if (! is_numeric($gcProbability)) { throw new Exception\InvalidArgumentException('Invalid gc_probability; must be numeric'); } $gcProbability = (int) $gcProbability; @@ -308,7 +308,7 @@ public function setGcProbability($gcProbability) */ public function getGcProbability() { - if (!isset($this->options['gc_probability'])) { + if (! isset($this->options['gc_probability'])) { $this->options['gc_probability'] = $this->getStorageOption('gc_probability'); } @@ -324,7 +324,7 @@ public function getGcProbability() */ public function setGcDivisor($gcDivisor) { - if (!is_numeric($gcDivisor)) { + if (! is_numeric($gcDivisor)) { throw new Exception\InvalidArgumentException('Invalid gc_divisor; must be numeric'); } $gcDivisor = (int) $gcDivisor; @@ -343,7 +343,7 @@ public function setGcDivisor($gcDivisor) */ public function getGcDivisor() { - if (!isset($this->options['gc_divisor'])) { + if (! isset($this->options['gc_divisor'])) { $this->options['gc_divisor'] = $this->getStorageOption('gc_divisor'); } @@ -359,7 +359,7 @@ public function getGcDivisor() */ public function setGcMaxlifetime($gcMaxlifetime) { - if (!is_numeric($gcMaxlifetime)) { + if (! is_numeric($gcMaxlifetime)) { throw new Exception\InvalidArgumentException('Invalid gc_maxlifetime; must be numeric'); } @@ -380,7 +380,7 @@ public function setGcMaxlifetime($gcMaxlifetime) */ public function getGcMaxlifetime() { - if (!isset($this->options['gc_maxlifetime'])) { + if (! isset($this->options['gc_maxlifetime'])) { $this->options['gc_maxlifetime'] = $this->getStorageOption('gc_maxlifetime'); } @@ -396,7 +396,7 @@ public function getGcMaxlifetime() */ public function setCookieLifetime($cookieLifetime) { - if (!is_numeric($cookieLifetime)) { + if (! is_numeric($cookieLifetime)) { throw new Exception\InvalidArgumentException('Invalid cookie_lifetime; must be numeric'); } if (0 > $cookieLifetime) { @@ -466,13 +466,13 @@ public function getCookiePath() */ public function setCookieDomain($cookieDomain) { - if (!is_string($cookieDomain)) { + if (! is_string($cookieDomain)) { throw new Exception\InvalidArgumentException('Invalid cookie domain: must be a string'); } $validator = new HostnameValidator(HostnameValidator::ALLOW_ALL); - if (!empty($cookieDomain) && !$validator->isValid($cookieDomain)) { + if (! empty($cookieDomain) && ! $validator->isValid($cookieDomain)) { throw new Exception\InvalidArgumentException( 'Invalid cookie domain: ' . implode('; ', $validator->getMessages()) ); @@ -586,7 +586,7 @@ public function getUseCookies() */ public function setEntropyFile($entropyFile) { - if (!is_readable($entropyFile)) { + if (! is_readable($entropyFile)) { throw new Exception\InvalidArgumentException(sprintf( "Invalid entropy_file provided: '%s'; doesn't exist or not readable", $entropyFile @@ -605,7 +605,7 @@ public function setEntropyFile($entropyFile) */ public function getEntropyFile() { - if (!isset($this->options['entropy_file'])) { + if (! isset($this->options['entropy_file'])) { $this->options['entropy_file'] = $this->getStorageOption('entropy_file'); } @@ -621,7 +621,7 @@ public function getEntropyFile() */ public function setEntropyLength($entropyLength) { - if (!is_numeric($entropyLength)) { + if (! is_numeric($entropyLength)) { throw new Exception\InvalidArgumentException('Invalid entropy_length; must be numeric'); } if (0 > $entropyLength) { @@ -640,7 +640,7 @@ public function setEntropyLength($entropyLength) */ public function getEntropyLength() { - if (!isset($this->options['entropy_length'])) { + if (! isset($this->options['entropy_length'])) { $this->options['entropy_length'] = $this->getStorageOption('entropy_length'); } @@ -656,7 +656,7 @@ public function getEntropyLength() */ public function setCacheExpire($cacheExpire) { - if (!is_numeric($cacheExpire)) { + if (! is_numeric($cacheExpire)) { throw new Exception\InvalidArgumentException('Invalid cache_expire; must be numeric'); } @@ -677,7 +677,7 @@ public function setCacheExpire($cacheExpire) */ public function getCacheExpire() { - if (!isset($this->options['cache_expire'])) { + if (! isset($this->options['cache_expire'])) { $this->options['cache_expire'] = $this->getStorageOption('cache_expire'); } @@ -693,7 +693,7 @@ public function getCacheExpire() */ public function setHashBitsPerCharacter($hashBitsPerCharacter) { - if (!is_numeric($hashBitsPerCharacter)) { + if (! is_numeric($hashBitsPerCharacter)) { throw new Exception\InvalidArgumentException('Invalid hash bits per character provided'); } $hashBitsPerCharacter = (int) $hashBitsPerCharacter; @@ -709,7 +709,7 @@ public function setHashBitsPerCharacter($hashBitsPerCharacter) */ public function getHashBitsPerCharacter() { - if (!isset($this->options['hash_bits_per_character'])) { + if (! isset($this->options['hash_bits_per_character'])) { $this->options['hash_bits_per_character'] = $this->getStorageOption('hash_bits_per_character'); } @@ -725,7 +725,7 @@ public function getHashBitsPerCharacter() */ public function setRememberMeSeconds($rememberMeSeconds) { - if (!is_numeric($rememberMeSeconds)) { + if (! is_numeric($rememberMeSeconds)) { throw new Exception\InvalidArgumentException('Invalid remember_me_seconds; must be numeric'); } diff --git a/src/Container.php b/src/Container.php index 9957ae72..f650a6cf 100644 --- a/src/Container.php +++ b/src/Container.php @@ -28,7 +28,7 @@ class Container extends AbstractContainer public function &offsetGet($key) { $ret = null; - if (!$this->offsetExists($key)) { + if (! $this->offsetExists($key)) { return $ret; } $storage = $this->getStorage(); diff --git a/src/SaveHandler/MongoDB.php b/src/SaveHandler/MongoDB.php index 1400a984..9bac9c89 100644 --- a/src/SaveHandler/MongoDB.php +++ b/src/SaveHandler/MongoDB.php @@ -127,7 +127,7 @@ public function read($id) if (null !== $session) { // check if session has expired if index is not used - if (!$this->options->useExpireAfterSecondsIndex()) { + if (! $this->options->useExpireAfterSecondsIndex()) { $timestamp = $session[$this->options->getLifetimeField()]; $timestamp += floor(((string)$session[$this->options->getModifiedField()]) / 1000); diff --git a/src/Service/ContainerAbstractServiceFactory.php b/src/Service/ContainerAbstractServiceFactory.php index 159cf45d..113cd99f 100644 --- a/src/Service/ContainerAbstractServiceFactory.php +++ b/src/Service/ContainerAbstractServiceFactory.php @@ -125,7 +125,7 @@ protected function getConfig(ContainerInterface $container) return $this->config; } - if (!$container->has('config')) { + if (! $container->has('config')) { $this->config = []; return $this->config; } diff --git a/src/Service/SessionManagerFactory.php b/src/Service/SessionManagerFactory.php index 0d560188..ab76088f 100644 --- a/src/Service/SessionManagerFactory.php +++ b/src/Service/SessionManagerFactory.php @@ -72,7 +72,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o if ($container->has(ConfigInterface::class)) { $config = $container->get(ConfigInterface::class); - if (!$config instanceof ConfigInterface) { + if (! $config instanceof ConfigInterface) { throw new ServiceNotCreatedException(sprintf( 'SessionManager requires that the %s service implement %s; received "%s"', ConfigInterface::class, @@ -84,7 +84,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o if ($container->has(StorageInterface::class)) { $storage = $container->get(StorageInterface::class); - if (!$storage instanceof StorageInterface) { + if (! $storage instanceof StorageInterface) { throw new ServiceNotCreatedException(sprintf( 'SessionManager requires that the %s service implement %s; received "%s"', StorageInterface::class, @@ -96,7 +96,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o if ($container->has(SaveHandlerInterface::class)) { $saveHandler = $container->get(SaveHandlerInterface::class); - if (!$saveHandler instanceof SaveHandlerInterface) { + if (! $saveHandler instanceof SaveHandlerInterface) { throw new ServiceNotCreatedException(sprintf( 'SessionManager requires that the %s service implement %s; received "%s"', SaveHandlerInterface::class, diff --git a/src/SessionManager.php b/src/SessionManager.php index 52cc4b55..410b69b6 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -141,7 +141,7 @@ public function start($preserveStorage = false) // Since session is starting, we need to potentially repopulate our // session storage if ($storage instanceof Storage\SessionStorage && $_SESSION !== $storage) { - if (!$preserveStorage) { + if (! $preserveStorage) { $storage->fromArray($_SESSION); } $_SESSION = $storage; @@ -151,7 +151,7 @@ public function start($preserveStorage = false) $this->initializeValidatorChain(); - if (!$this->isValid()) { + if (! $this->isValid()) { throw new Exception\RuntimeException('Session validation failed'); } } @@ -183,7 +183,7 @@ protected function initializeValidatorChain() */ public function destroy(array $options = null) { - if (!$this->sessionExists()) { + if (! $this->sessionExists()) { return; } @@ -224,7 +224,7 @@ public function writeClose() // flushed to the session handler. As such, we now mark the storage // object isImmutable. $storage = $this->getStorage(); - if (!$storage->isImmutable()) { + if (! $storage->isImmutable()) { $_SESSION = $storage->toArray(true); session_write_close(); $storage->fromArray($_SESSION); @@ -250,7 +250,7 @@ public function setName($name) ); } - if (!preg_match('/^[a-zA-Z0-9]+$/', $name)) { + if (! preg_match('/^[a-zA-Z0-9]+$/', $name)) { throw new Exception\InvalidArgumentException( 'Name provided contains invalid characters; must be alphanumeric only' ); @@ -291,7 +291,9 @@ public function getName() public function setId($id) { if ($this->sessionExists()) { - throw new Exception\RuntimeException('Session has already been started, to change the session ID call regenerateId()'); + throw new Exception\RuntimeException( + 'Session has already been started, to change the session ID call regenerateId()' + ); } session_id($id); return $this; @@ -428,7 +430,7 @@ public function isValid() public function expireSessionCookie() { $config = $this->getConfig(); - if (!$config->getUseCookies()) { + if (! $config->getUseCookies()) { return; } setcookie( @@ -454,7 +456,7 @@ public function expireSessionCookie() protected function setSessionCookieLifetime($ttl) { $config = $this->getConfig(); - if (!$config->getUseCookies()) { + if (! $config->getUseCookies()) { return; } diff --git a/src/Storage/AbstractSessionArrayStorage.php b/src/Storage/AbstractSessionArrayStorage.php index b708bf1b..a0be9502 100644 --- a/src/Storage/AbstractSessionArrayStorage.php +++ b/src/Storage/AbstractSessionArrayStorage.php @@ -45,7 +45,7 @@ public function init($input = null) { if ((null === $input) && isset($_SESSION)) { $input = $_SESSION; - if (is_object($input) && !$_SESSION instanceof \ArrayObject) { + if (is_object($input) && ! $_SESSION instanceof \ArrayObject) { $input = (array) $input; } } elseif (null === $input) { @@ -280,7 +280,7 @@ public function isLocked($key = null) $locks = $this->getMetadata('_LOCKS'); $readOnly = $this->getMetadata('_READONLY'); - if ($readOnly && !$locks) { + if ($readOnly && ! $locks) { // global lock in play; all keys are locked return true; } @@ -289,7 +289,7 @@ public function isLocked($key = null) } // test for individual locks - if (!$locks) { + if (! $locks) { return false; } @@ -313,8 +313,8 @@ public function unlock($key = null) } $locks = $this->getMetadata('_LOCKS'); - if (!$locks) { - if (!$this->getMetadata('_READONLY')) { + if (! $locks) { + if (! $this->getMetadata('_READONLY')) { return $this; } $array = $this->toArray(); @@ -355,7 +355,7 @@ public function setMetadata($key, $value, $overwriteArray = false) ); } - if (!isset($_SESSION['__ZF'])) { + if (! isset($_SESSION['__ZF'])) { $_SESSION['__ZF'] = []; } if (isset($_SESSION['__ZF'][$key]) && is_array($value)) { @@ -389,7 +389,7 @@ public function setMetadata($key, $value, $overwriteArray = false) */ public function getMetadata($key = null) { - if (!isset($_SESSION['__ZF'])) { + if (! isset($_SESSION['__ZF'])) { return false; } @@ -397,7 +397,7 @@ public function getMetadata($key = null) return $_SESSION['__ZF']; } - if (!array_key_exists($key, $_SESSION['__ZF'])) { + if (! array_key_exists($key, $_SESSION['__ZF'])) { return false; } @@ -422,7 +422,7 @@ public function clear($key = null) return $this; } - if (!isset($_SESSION[$key])) { + if (! isset($_SESSION[$key])) { return $this; } diff --git a/src/Storage/ArrayStorage.php b/src/Storage/ArrayStorage.php index 8bd514a9..6e7ec158 100644 --- a/src/Storage/ArrayStorage.php +++ b/src/Storage/ArrayStorage.php @@ -141,7 +141,7 @@ public function isLocked($key = null) $locks = $this->getMetadata('_LOCKS'); $readOnly = $this->getMetadata('_READONLY'); - if ($readOnly && !$locks) { + if ($readOnly && ! $locks) { // global lock in play; all keys are locked return true; } elseif ($readOnly && $locks) { @@ -149,7 +149,7 @@ public function isLocked($key = null) } // test for individual locks - if (!$locks) { + if (! $locks) { return false; } @@ -173,8 +173,8 @@ public function unlock($key = null) } $locks = $this->getMetadata('_LOCKS'); - if (!$locks) { - if (!$this->getMetadata('_READONLY')) { + if (! $locks) { + if (! $this->getMetadata('_READONLY')) { return $this; } $array = $this->toArray(); @@ -237,7 +237,7 @@ public function setMetadata($key, $value, $overwriteArray = false) ); } - if (!isset($this['__ZF'])) { + if (! isset($this['__ZF'])) { $this['__ZF'] = []; } @@ -275,7 +275,7 @@ public function setMetadata($key, $value, $overwriteArray = false) */ public function getMetadata($key = null) { - if (!isset($this['__ZF'])) { + if (! isset($this['__ZF'])) { return false; } @@ -283,7 +283,7 @@ public function getMetadata($key = null) return $this['__ZF']; } - if (!array_key_exists($key, $this['__ZF'])) { + if (! array_key_exists($key, $this['__ZF'])) { return false; } @@ -308,7 +308,7 @@ public function clear($key = null) return $this; } - if (!isset($this[$key])) { + if (! isset($this[$key])) { return $this; } diff --git a/src/Storage/Factory.php b/src/Storage/Factory.php index 27aeeea0..caebee9f 100644 --- a/src/Storage/Factory.php +++ b/src/Storage/Factory.php @@ -27,16 +27,16 @@ abstract class Factory */ public static function factory($type, $options = []) { - if (!is_string($type)) { + if (! is_string($type)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects the $type argument to be a string class name; received "%s"', __METHOD__, (is_object($type) ? get_class($type) : gettype($type)) )); } - if (!class_exists($type)) { + if (! class_exists($type)) { $class = __NAMESPACE__ . '\\' . $type; - if (!class_exists($class)) { + if (! class_exists($class)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects the $type argument to be a valid class name; received "%s"', __METHOD__, @@ -49,7 +49,7 @@ public static function factory($type, $options = []) if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } - if (!is_array($options)) { + if (! is_array($options)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects the $options argument to be an array or Traversable; received "%s"', __METHOD__, @@ -88,7 +88,7 @@ protected static function createArrayStorage($type, $options) $iteratorClass = 'ArrayIterator'; if (isset($options['input']) && null !== $options['input']) { - if (!is_array($options['input'])) { + if (! is_array($options['input'])) { throw new Exception\InvalidArgumentException(sprintf( '%s expects the "input" option to be an array; received "%s"', $type, @@ -103,11 +103,14 @@ protected static function createArrayStorage($type, $options) } if (isset($options['iterator_class'])) { - if (!class_exists($options['iterator_class'])) { + if (! class_exists($options['iterator_class'])) { throw new Exception\InvalidArgumentException(sprintf( '%s expects the "iterator_class" option to be a valid class; received "%s"', $type, - (is_object($options['iterator_class']) ? get_class($options['iterator_class']) : gettype($options['iterator_class'])) + (is_object($options['iterator_class']) + ? get_class($options['iterator_class']) + : gettype($options['iterator_class']) + ) )); } $iteratorClass = $options['iterator_class']; @@ -129,8 +132,8 @@ protected static function createSessionArrayStorage($type, array $options) $input = null; if (isset($options['input'])) { if (null !== $options['input'] - && !is_array($options['input']) - && !$input instanceof ArrayAccess + && ! is_array($options['input']) + && ! $input instanceof ArrayAccess ) { throw new Exception\InvalidArgumentException(sprintf( '%s expects the "input" option to be null, an array, or to implement ArrayAccess; received "%s"', diff --git a/src/Storage/SessionStorage.php b/src/Storage/SessionStorage.php index 39dad7c0..f3f74f85 100644 --- a/src/Storage/SessionStorage.php +++ b/src/Storage/SessionStorage.php @@ -36,7 +36,7 @@ public function __construct($input = null, $flags = ArrayObject::ARRAY_AS_PROPS, $input = $_SESSION; if (is_object($input) && $_SESSION instanceof ArrayObject) { $resetSession = false; - } elseif (is_object($input) && !$_SESSION instanceof ArrayObject) { + } elseif (is_object($input) && ! $_SESSION instanceof ArrayObject) { $input = (array) $input; } } elseif (null === $input) { diff --git a/src/compatibility/autoload.php b/src/compatibility/autoload.php index 287c6ba0..77f85917 100644 --- a/src/compatibility/autoload.php +++ b/src/compatibility/autoload.php @@ -11,4 +11,5 @@ /** * Legacy purposes only, to prevent code that references it from breaking. */ -trigger_error('Polyfill autoload support (file library/Zend/Session/compatibility/autoload.php) is no longer necessary; please remove your require statement referencing this file', E_USER_DEPRECATED); +trigger_error('Polyfill autoload support (file library/Zend/Session/compatibility/autoload.php) is no longer necessary;' +. ' please remove your require statement referencing this file', E_USER_DEPRECATED); diff --git a/test/Config/SessionConfigTest.php b/test/Config/SessionConfigTest.php index a349743a..0d19179e 100644 --- a/test/Config/SessionConfigTest.php +++ b/test/Config/SessionConfigTest.php @@ -82,7 +82,11 @@ public function testNameAltersIniSetting() public function testSaveHandlerDefaultsToIniSettings() { - $this->assertSame(ini_get('session.save_handler'), $this->config->getSaveHandler(), var_export($this->config->toArray(), 1)); + $this->assertSame( + ini_get('session.save_handler'), + $this->config->getSaveHandler(), + var_export($this->config->toArray(), 1) + ); } public function testSaveHandlerIsMutable() @@ -99,7 +103,10 @@ public function testSaveHandlerAltersIniSetting() public function testSettingInvalidSaveHandlerRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid save handler specified'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid save handler specified' + ); $this->config->setPhpSaveHandler('foobar_bogus'); } @@ -124,19 +131,28 @@ public function testGcProbabilityAltersIniSetting() public function testSettingInvalidGcProbabilityRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_probability; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_probability; must be numeric' + ); $this->config->setGcProbability('foobar_bogus'); } public function testSettingInvalidGcProbabilityRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_probability; must be a percentage'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_probability; must be a percentage' + ); $this->config->setGcProbability(-1); } public function testSettingInvalidGcProbabilityRaisesException3() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_probability; must be a percentage'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_probability; must be a percentage' + ); $this->config->setGcProbability(101); } @@ -161,13 +177,19 @@ public function testGcDivisorAltersIniSetting() public function testSettingInvalidGcDivisorRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_divisor; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_divisor; must be numeric' + ); $this->config->setGcDivisor('foobar_bogus'); } public function testSettingInvalidGcDivisorRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_divisor; must be a positive integer'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_divisor; must be a positive integer' + ); $this->config->setGcDivisor(-1); } @@ -192,13 +214,19 @@ public function testGcMaxlifetimeAltersIniSetting() public function testSettingInvalidGcMaxlifetimeRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_maxlifetime; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_maxlifetime; must be numeric' + ); $this->config->setGcMaxlifetime('foobar_bogus'); } public function testSettingInvalidGcMaxlifetimeRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_maxlifetime; must be a positive integer'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_maxlifetime; must be a positive integer' + ); $this->config->setGcMaxlifetime(-1); } @@ -225,7 +253,10 @@ public function testSerializeHandlerAltersIniSetting() public function testSettingInvalidSerializeHandlerRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid serialize handler specified'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid serialize handler specified' + ); $this->config->setSerializeHandler('foobar_bogus'); } @@ -256,13 +287,19 @@ public function testCookieLifetimeCanBeZero() public function testSettingInvalidCookieLifetimeRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cookie_lifetime; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cookie_lifetime; must be numeric' + ); $this->config->setCookieLifetime('foobar_bogus'); } public function testSettingInvalidCookieLifetimeRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cookie_lifetime; must be a positive integer or zero'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cookie_lifetime; must be a positive integer or zero' + ); $this->config->setCookieLifetime(-1); } @@ -330,13 +367,19 @@ public function testCookieDomainAltersIniSetting() public function testSettingInvalidCookieDomainRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cookie domain: must be a string'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cookie domain: must be a string' + ); $this->config->setCookieDomain(24); } public function testSettingInvalidCookieDomainRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'does not match the expected structure for a DNS hostname'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'does not match the expected structure for a DNS hostname' + ); $this->config->setCookieDomain('D:\\WINDOWS\\System32\\drivers\\etc\\hosts'); } @@ -349,14 +392,14 @@ public function testCookieSecureDefaultsToIniSettings() public function testCookieSecureIsMutable() { - $value = !ini_get('session.cookie_secure'); + $value = ! ini_get('session.cookie_secure'); $this->config->setCookieSecure($value); $this->assertEquals($value, $this->config->getCookieSecure()); } public function testCookieSecureAltersIniSetting() { - $value = !ini_get('session.cookie_secure'); + $value = ! ini_get('session.cookie_secure'); $this->config->setCookieSecure($value); $this->assertEquals($value, ini_get('session.cookie_secure')); } @@ -370,14 +413,14 @@ public function testCookieHttpOnlyDefaultsToIniSettings() public function testCookieHttpOnlyIsMutable() { - $value = !ini_get('session.cookie_httponly'); + $value = ! ini_get('session.cookie_httponly'); $this->config->setCookieHttpOnly($value); $this->assertEquals($value, $this->config->getCookieHttpOnly()); } public function testCookieHttpOnlyAltersIniSetting() { - $value = !ini_get('session.cookie_httponly'); + $value = ! ini_get('session.cookie_httponly'); $this->config->setCookieHttpOnly($value); $this->assertEquals($value, ini_get('session.cookie_httponly')); } @@ -391,14 +434,14 @@ public function testUseCookiesDefaultsToIniSettings() public function testUseCookiesIsMutable() { - $value = !ini_get('session.use_cookies'); + $value = ! ini_get('session.use_cookies'); $this->config->setUseCookies($value); $this->assertEquals($value, $this->config->getUseCookies()); } public function testUseCookiesAltersIniSetting() { - $value = !ini_get('session.use_cookies'); + $value = ! ini_get('session.use_cookies'); $this->config->setUseCookies($value); $this->assertEquals($value, (bool) ini_get('session.use_cookies')); } @@ -412,14 +455,14 @@ public function testUseOnlyCookiesDefaultsToIniSettings() public function testUseOnlyCookiesIsMutable() { - $value = !ini_get('session.use_only_cookies'); + $value = ! ini_get('session.use_only_cookies'); $this->config->setOption('use_only_cookies', $value); $this->assertEquals($value, (bool) $this->config->getOption('use_only_cookies')); } public function testUseOnlyCookiesAltersIniSetting() { - $value = !ini_get('session.use_only_cookies'); + $value = ! ini_get('session.use_only_cookies'); $this->config->setOption('use_only_cookies', $value); $this->assertEquals($value, (bool) ini_get('session.use_only_cookies')); } @@ -501,15 +544,19 @@ public function testEntropyLengthCanBeZero() public function testSettingInvalidEntropyLengthRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', - 'Invalid entropy_length; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid entropy_length; must be numeric' + ); $this->config->setEntropyLength('foobar_bogus'); } public function testSettingInvalidEntropyLengthRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', - 'Invalid entropy_length; must be a positive integer or zero'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid entropy_length; must be a positive integer or zero' + ); $this->config->setEntropyLength(-1); } @@ -551,7 +598,10 @@ public function testCacheLimiterAltersIniSetting($cacheLimiter) public function testSettingInvalidCacheLimiterRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cache limiter provided'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cache limiter provided' + ); $this->config->setCacheLimiter('foobar_bogus'); } @@ -576,13 +626,19 @@ public function testCacheExpireAltersIniSetting() public function testSettingInvalidCacheExpireRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cache_expire; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cache_expire; must be numeric' + ); $this->config->setCacheExpire('foobar_bogus'); } public function testSettingInvalidCacheExpireRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cache_expire; must be a positive integer'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cache_expire; must be a positive integer' + ); $this->config->setCacheExpire(-1); } @@ -595,14 +651,14 @@ public function testUseTransSidDefaultsToIniSettings() public function testUseTransSidIsMutable() { - $value = !ini_get('session.use_trans_sid'); + $value = ! ini_get('session.use_trans_sid'); $this->config->setOption('use_trans_sid', $value); $this->assertEquals($value, (bool) $this->config->getOption('use_trans_sid')); } public function testUseTransSidAltersIniSetting() { - $value = !ini_get('session.use_trans_sid'); + $value = ! ini_get('session.use_trans_sid'); $this->config->setOption('use_trans_sid', $value); $this->assertEquals($value, (bool) ini_get('session.use_trans_sid')); } @@ -644,7 +700,10 @@ public function testHashFunctionAltersIniSetting($hashFunction) public function testSettingInvalidHashFunctionRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid hash function provided'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid hash function provided' + ); $this->config->setHashFunction('foobar_bogus'); } @@ -684,8 +743,10 @@ public function testHashBitsPerCharacterAltersIniSetting($hashBitsPerCharacter) public function testSettingInvalidHashBitsPerCharacterRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', - 'Invalid hash bits per character provided'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid hash bits per character provided' + ); $this->config->setHashBitsPerCharacter('foobar_bogus'); } diff --git a/test/Config/StandardConfigTest.php b/test/Config/StandardConfigTest.php index a1a8ab1b..168d7df1 100644 --- a/test/Config/StandardConfigTest.php +++ b/test/Config/StandardConfigTest.php @@ -72,19 +72,28 @@ public function testGcProbabilityCanBeSetToZero() public function testSettingInvalidGcProbabilityRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_probability; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_probability; must be numeric' + ); $this->config->setGcProbability('foobar_bogus'); } public function testSettingInvalidGcProbabilityRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_probability; must be a percentage'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_probability; must be a percentage' + ); $this->config->setGcProbability(-1); } public function testSettingInvalidGcProbabilityRaisesException3() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_probability; must be a percentage'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_probability; must be a percentage' + ); $this->config->setGcProbability(101); } @@ -98,13 +107,19 @@ public function testGcDivisorIsMutable() public function testSettingInvalidGcDivisorRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_divisor; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_divisor; must be numeric' + ); $this->config->setGcDivisor('foobar_bogus'); } public function testSettingInvalidGcDivisorRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_divisor; must be a positive integer'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_divisor; must be a positive integer' + ); $this->config->setGcDivisor(-1); } @@ -118,13 +133,19 @@ public function testGcMaxlifetimeIsMutable() public function testSettingInvalidGcMaxlifetimeRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_maxlifetime; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_maxlifetime; must be numeric' + ); $this->config->setGcMaxlifetime('foobar_bogus'); } public function testSettingInvalidGcMaxlifetimeRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid gc_maxlifetime; must be a positive integer'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid gc_maxlifetime; must be a positive integer' + ); $this->config->setGcMaxlifetime(-1); } @@ -153,13 +174,19 @@ public function testCookieLifetimeCanBeZero() public function testSettingInvalidCookieLifetimeRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cookie_lifetime; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cookie_lifetime; must be numeric' + ); $this->config->setCookieLifetime('foobar_bogus'); } public function testSettingInvalidCookieLifetimeRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cookie_lifetime; must be a positive integer or zero'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cookie_lifetime; must be a positive integer or zero' + ); $this->config->setCookieLifetime(-1); } @@ -205,13 +232,19 @@ public function testCookieDomainCanBeEmpty() public function testSettingInvalidCookieDomainRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid cookie domain: must be a string'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cookie domain: must be a string' + ); $this->config->setCookieDomain(24); } public function testSettingInvalidCookieDomainRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'does not match the expected structure for a DNS hostname'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'does not match the expected structure for a DNS hostname' + ); $this->config->setCookieDomain('D:\\WINDOWS\\System32\\drivers\\etc\\hosts'); } @@ -291,13 +324,19 @@ public function testEntropyLengthCanBeZero() public function testSettingInvalidEntropyLengthRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid entropy_length; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid entropy_length; must be numeric' + ); $this->config->setEntropyLength('foobar_bogus'); } public function testSettingInvalidEntropyLengthRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Invalid entropy_length; must be a positive integer or zero'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid entropy_length; must be a positive integer or zero' + ); $this->config->setEntropyLength(-1); } @@ -332,15 +371,19 @@ public function testCacheExpireIsMutable() public function testSettingInvalidCacheExpireRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', - 'Invalid cache_expire; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cache_expire; must be numeric' + ); $this->config->setCacheExpire('foobar_bogus'); } public function testSettingInvalidCacheExpireRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', - 'Invalid cache_expire; must be a positive integer'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid cache_expire; must be a positive integer' + ); $this->config->setCacheExpire(-1); } @@ -395,8 +438,10 @@ public function testHashBitsPerCharacterIsMutable($hashBitsPerCharacter) public function testSettingInvalidHashBitsPerCharacterRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', - 'Invalid hash bits per character provided'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid hash bits per character provided' + ); $this->config->setHashBitsPerCharacter('foobar_bogus'); } @@ -418,15 +463,19 @@ public function testRememberMeSecondsIsMutable() public function testSettingInvalidRememberMeSecondsRaisesException() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', - 'Invalid remember_me_seconds; must be numeric'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid remember_me_seconds; must be numeric' + ); $this->config->setRememberMeSeconds('foobar_bogus'); } public function testSettingInvalidRememberMeSecondsRaisesException2() { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', - 'Invalid remember_me_seconds; must be a positive integer'); + $this->setExpectedException( + 'Zend\Session\Exception\InvalidArgumentException', + 'Invalid remember_me_seconds; must be a positive integer' + ); $this->config->setRememberMeSeconds(-1); } @@ -570,7 +619,7 @@ public function optionsProvider() */ public function testSetEntropyDevUrandom() { - if (!file_exists('/dev/urandom')) { + if (! file_exists('/dev/urandom')) { $this->markTestSkipped( "This test doesn't work because /dev/urandom file doesn't exist." ); diff --git a/test/ContainerTest.php b/test/ContainerTest.php index 9e5a9019..88e53ba7 100644 --- a/test/ContainerTest.php +++ b/test/ContainerTest.php @@ -229,8 +229,8 @@ public function testMultipleCallsToExpirationSecondsAggregates() $storage = $this->manager->getStorage(); $metadata = $storage->getMetadata($this->container->getName()); $this->assertEquals($_SERVER['REQUEST_TIME'] + 1800, $metadata['EXPIRE_KEYS']['foo']); - $this->assertEquals($_SERVER['REQUEST_TIME'] + 900, $metadata['EXPIRE_KEYS']['baz']); - $this->assertEquals($_SERVER['REQUEST_TIME'] + 900, $metadata['EXPIRE_KEYS']['bat']); + $this->assertEquals($_SERVER['REQUEST_TIME'] + 900, $metadata['EXPIRE_KEYS']['baz']); + $this->assertEquals($_SERVER['REQUEST_TIME'] + 900, $metadata['EXPIRE_KEYS']['bat']); $this->assertEquals($_SERVER['REQUEST_TIME'] + 3600, $metadata['EXPIRE']); } @@ -494,7 +494,7 @@ public function testIterationHonorsExpirationTimestamps() $expected = ['bar' => 'baz']; $test = []; foreach ($this->container as $key => $value) { - $test[$key] = $value; + $test[$key] = $value; } $this->assertSame($expected, $test); } @@ -551,7 +551,7 @@ public function testUpgradeBehaviors() public function testGetArrayCopyAfterExchangeArray() { - $this->container->exchangeArray(['foo'=>'bar']); + $this->container->exchangeArray(['foo' => 'bar']); $contents = $this->container->getArrayCopy(); diff --git a/test/SaveHandler/CacheTest.php b/test/SaveHandler/CacheTest.php index 57afb03a..a83ac567 100644 --- a/test/SaveHandler/CacheTest.php +++ b/test/SaveHandler/CacheTest.php @@ -52,8 +52,7 @@ public function testReadWrite() ->will(function ($args) { $this->getItem('242')->willReturn($args[1]); return true; - } - ); + }); $this->usedSaveHandlers[] = $saveHandler = new Cache($cacheStorage->reveal()); $id = '242'; @@ -61,7 +60,11 @@ public function testReadWrite() $this->assertTrue($saveHandler->write($id, serialize($this->testArray))); $data = unserialize($saveHandler->read($id)); - $this->assertEquals($this->testArray, $data, 'Expected ' . var_export($this->testArray, 1) . "\nbut got: " . var_export($data, 1)); + $this->assertEquals( + $this->testArray, + $data, + 'Expected ' . var_export($this->testArray, 1) . "\nbut got: " . var_export($data, 1) + ); } public function testReadWriteComplex() diff --git a/test/SaveHandler/DbTableGatewayTest.php b/test/SaveHandler/DbTableGatewayTest.php index 2e6c01da..45c1a763 100644 --- a/test/SaveHandler/DbTableGatewayTest.php +++ b/test/SaveHandler/DbTableGatewayTest.php @@ -62,8 +62,10 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase */ public function setUp() { - if (!extension_loaded('pdo_sqlite')) { - $this->markTestSkipped('Zend\Session\SaveHandler\DbTableGateway tests are not enabled due to missing PDO_Sqlite extension'); + if (! extension_loaded('pdo_sqlite')) { + $this->markTestSkipped( + 'Zend\Session\SaveHandler\DbTableGateway tests are not enabled due to missing PDO_Sqlite extension' + ); } $this->options = new DbTableGatewayOptions([ @@ -100,7 +102,11 @@ public function testReadWrite() $this->assertTrue($saveHandler->write($id, serialize($this->testArray))); $data = unserialize($saveHandler->read($id)); - $this->assertEquals($this->testArray, $data, 'Expected ' . var_export($this->testArray, 1) . "\nbut got: " . var_export($data, 1)); + $this->assertEquals( + $this->testArray, + $data, + 'Expected ' . var_export($this->testArray, 1) . "\nbut got: " . var_export($data, 1) + ); } public function testReadWriteComplex() @@ -185,7 +191,10 @@ public function testExpiredSessionDoesNotCauseARecursion() "; $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE); - $this->usedSaveHandlers[] = $saveHandler = new TestDbTableGatewaySaveHandler($this->tableGateway, $this->options); + $this->usedSaveHandlers[] = $saveHandler = new TestDbTableGatewaySaveHandler( + $this->tableGateway, + $this->options + ); $saveHandler->open('savepath', 'zend-session-test'); $this->assertSame(0, $saveHandler->getNumReadCalls()); @@ -236,7 +245,7 @@ protected function setupDb(DbTableGatewayOptions $options) */ protected function dropTable() { - if (!$this->adapter) { + if (! $this->adapter) { return; } $this->adapter->query('DROP TABLE sessions', Adapter::QUERY_MODE_EXECUTE); diff --git a/test/SessionManagerTest.php b/test/SessionManagerTest.php index 487d4a23..97570f1d 100644 --- a/test/SessionManagerTest.php +++ b/test/SessionManagerTest.php @@ -250,7 +250,10 @@ public function testGetNameReturnsSessionName() */ public function testSetNameRaisesExceptionOnInvalidName() { - $this->setExpectedException(InvalidArgumentException::class, 'Name provided contains invalid characters; must be alphanumeric only'); + $this->setExpectedException( + InvalidArgumentException::class, + 'Name provided contains invalid characters; must be alphanumeric only' + ); $this->manager->setName('foo bar!'); } @@ -294,7 +297,7 @@ public function testSettingNameWhenAnActiveSessionExistsRaisesException() */ public function testDestroyByDefaultSendsAnExpireCookie() { - if (!extension_loaded('xdebug')) { + if (! extension_loaded('xdebug')) { $this->markTestSkipped('Xdebug required for this test'); } @@ -319,7 +322,7 @@ public function testDestroyByDefaultSendsAnExpireCookie() */ public function testSendingFalseToSendExpireCookieWhenCallingDestroyShouldNotSendCookie() { - if (!extension_loaded('xdebug')) { + if (! extension_loaded('xdebug')) { $this->markTestSkipped('Xdebug required for this test'); } @@ -449,7 +452,7 @@ public function testRegenerateIdDoesNothingWhenSessioIsNotStarted() */ public function testRegeneratingIdAfterSessionStartedShouldSendExpireCookie() { - if (!extension_loaded('xdebug')) { + if (! extension_loaded('xdebug')) { $this->markTestSkipped('Xdebug required for this test'); } @@ -474,7 +477,7 @@ public function testRegeneratingIdAfterSessionStartedShouldSendExpireCookie() */ public function testRememberMeShouldSendNewSessionCookieWithUpdatedTimestamp() { - if (!extension_loaded('xdebug')) { + if (! extension_loaded('xdebug')) { $this->markTestSkipped('Xdebug required for this test'); } @@ -487,17 +490,21 @@ public function testRememberMeShouldSendNewSessionCookieWithUpdatedTimestamp() $sName = $this->manager->getName(); $cookie = false; foreach ($headers as $header) { - if (stristr($header, 'Set-Cookie:') && stristr($header, $sName) && !stristr($header, '=deleted')) { + if (stristr($header, 'Set-Cookie:') && stristr($header, $sName) && ! stristr($header, '=deleted')) { $found = true; $cookie = $header; } } $this->assertTrue($found, 'No session cookie found: ' . var_export($headers, true)); $ts = $this->getTimestampFromCookie($cookie); - if (!$ts) { + if (! $ts) { $this->fail('Cookie did not contain expiry? ' . var_export($headers, true)); } - $this->assertGreaterThan($_SERVER['REQUEST_TIME'], $ts->getTimestamp(), 'Session cookie: ' . var_export($headers, 1)); + $this->assertGreaterThan( + $_SERVER['REQUEST_TIME'], + $ts->getTimestamp(), + 'Session cookie: ' . var_export($headers, 1) + ); } /** @@ -505,7 +512,7 @@ public function testRememberMeShouldSendNewSessionCookieWithUpdatedTimestamp() */ public function testRememberMeShouldSetTimestampBasedOnConfigurationByDefault() { - if (!extension_loaded('xdebug')) { + if (! extension_loaded('xdebug')) { $this->markTestSkipped('Xdebug required for this test'); } @@ -520,14 +527,14 @@ public function testRememberMeShouldSetTimestampBasedOnConfigurationByDefault() $sName = $this->manager->getName(); $cookie = false; foreach ($headers as $header) { - if (stristr($header, 'Set-Cookie:') && stristr($header, $sName) && !stristr($header, '=deleted')) { + if (stristr($header, 'Set-Cookie:') && stristr($header, $sName) && ! stristr($header, '=deleted')) { $found = true; $cookie = $header; } } $this->assertTrue($found, 'No session cookie found: ' . var_export($headers, true)); $ts = $this->getTimestampFromCookie($cookie); - if (!$ts) { + if (! $ts) { $this->fail('Cookie did not contain expiry? ' . var_export($headers, true)); } $compare = $_SERVER['REQUEST_TIME'] + $ttl; @@ -540,7 +547,7 @@ public function testRememberMeShouldSetTimestampBasedOnConfigurationByDefault() */ public function testForgetMeShouldSendCookieWithZeroTimestamp() { - if (!extension_loaded('xdebug')) { + if (! extension_loaded('xdebug')) { $this->markTestSkipped('Xdebug required for this test'); } @@ -552,7 +559,7 @@ public function testForgetMeShouldSendCookieWithZeroTimestamp() $found = false; $sName = $this->manager->getName(); foreach ($headers as $header) { - if (stristr($header, 'Set-Cookie:') && stristr($header, $sName) && !stristr($header, '=deleted')) { + if (stristr($header, 'Set-Cookie:') && stristr($header, $sName) && ! stristr($header, '=deleted')) { $found = true; } } diff --git a/test/StorageTest.php b/test/StorageTest.php index 779b6f70..fc80ab28 100644 --- a/test/StorageTest.php +++ b/test/StorageTest.php @@ -213,8 +213,10 @@ public function testClearWhenStorageMarkedImmutableRaisesException() $this->storage->foo = 'bar'; $this->storage->bar = 'baz'; $this->storage->markImmutable(); - $this->setExpectedException('Zend\Session\Exception\RuntimeException', - 'Cannot clear storage as it is marked immutable'); + $this->setExpectedException( + 'Zend\Session\Exception\RuntimeException', + 'Cannot clear storage as it is marked immutable' + ); $this->storage->clear(); } diff --git a/test/TestAsset/TestDbTableGatewaySaveHandler.php b/test/TestAsset/TestDbTableGatewaySaveHandler.php index 27811ebb..9cbcf901 100644 --- a/test/TestAsset/TestDbTableGatewaySaveHandler.php +++ b/test/TestAsset/TestDbTableGatewaySaveHandler.php @@ -16,12 +16,12 @@ class TestDbTableGatewaySaveHandler extends DbTableGateway protected $numReadCalls = 0; protected $numDestroyCalls = 0; - + public function getNumReadCalls() { return $this->numReadCalls; } - + public function getNumDestroyCalls() { return $this->numDestroyCalls; @@ -32,10 +32,10 @@ public function read($id, $destroyExpired = true) $this->numReadCalls++; return parent::read($id, $destroyExpired); } - + public function destroy($id) { $this->numDestroyCalls++; return parent::destroy($id); } -} \ No newline at end of file +} diff --git a/test/TestAsset/TestSaveHandler.php b/test/TestAsset/TestSaveHandler.php index b18a5b6d..9b3bfe49 100644 --- a/test/TestAsset/TestSaveHandler.php +++ b/test/TestAsset/TestSaveHandler.php @@ -14,20 +14,26 @@ class TestSaveHandler implements SaveHandler { public function open($save_path, $name) - {} + { + } public function close() - {} + { + } public function read($id) - {} + { + } public function write($id, $data) - {} + { + } public function destroy($id) - {} + { + } public function gc($maxlifetime) - {} + { + } }