Skip to content

Commit

Permalink
minimum php version is 5.6 now
Browse files Browse the repository at this point in the history
* use short array notation
* use ::class pseudo-constant
* use createMock for phpunit
* simplify tests setup
  • Loading branch information
dbu committed Jan 16, 2017
1 parent 0aa8838 commit 2f13903
Show file tree
Hide file tree
Showing 32 changed files with 427 additions and 414 deletions.
15 changes: 7 additions & 8 deletions .travis.yml
@@ -1,10 +1,7 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

sudo: false
Expand All @@ -15,15 +12,17 @@ cache:

env: SYMFONY_VERSION=3.2.*

global:
- SYMFONY_PHPUNIT_DIR=.phpunit SYMFONY_PHPUNIT_REMOVE="symfony/yaml"
- SYMFONY_PHPUNIT_VERSION=5.7

matrix:
include:
- php: 7.1
env: SYMFONY_VERSION=3.3.* DEPS=dev
- php: 5.5
env: SYMFONY_VERSION=2.8.* COMPOSER_FLAGS="--prefer-lowest"
- php: 5.6
env: SYMFONY_VERSION=2.7.*
- php: 5.6
env: SYMFONY_VERSION=2.8.* COMPOSER_FLAGS="--prefer-lowest"
- php: 7.1
env: SYMFONY_VERSION=3.1.*
finish_fast: true

Expand All @@ -36,7 +35,7 @@ before_install:

install: composer update --prefer-dist $COMPOSER_FLAGS

script: phpunit
script: vendor/bin/simple-phpunit

notifications:
irc: "irc.freenode.org#symfony-cmf"
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -12,13 +12,14 @@
}
],
"require": {
"php": "^5.5.9|^7.0",
"php": "^5.6.0|^7.0",
"symfony/routing": "^2.2|^3.0",
"symfony/http-kernel": "^2.2|^3.0",
"psr/log": "^1.0"
},
"require-dev": {
"symfony-cmf/testing": "^1.3|^2.0",
"symfony/phpunit-bridge": "^3.2",
"symfony/dependency-injection": "^2.0.5|^3.0",
"symfony/config": "^2.2|^3.0",
"symfony/event-dispatcher": "^2.1|^3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Candidates/Candidates.php
Expand Up @@ -43,7 +43,7 @@ class Candidates implements CandidatesInterface
* @param array $locales The locales to support
* @param int $limit A limit to apply to the candidates generated
*/
public function __construct(array $locales = array(), $limit = 20)
public function __construct(array $locales = [], $limit = 20)
{
$this->setLocales($locales);
$this->limit = $limit;
Expand Down Expand Up @@ -107,7 +107,7 @@ protected function determineLocale($url)
return false;
}

$matches = array();
$matches = [];
if (preg_match('#('.implode('|', $this->locales).')(/|$)#', $url, $matches)) {
return $matches[1];
}
Expand All @@ -128,7 +128,7 @@ protected function determineLocale($url)
*/
protected function getCandidatesFor($url, $prefix = '')
{
$candidates = array();
$candidates = [];
if ('/' !== $url) {
// handle format extension, like .html or .json
if (preg_match('/(.+)\.[a-z]+$/i', $url, $matches)) {
Expand Down
6 changes: 3 additions & 3 deletions src/ChainRouteCollection.php
Expand Up @@ -20,7 +20,7 @@ class ChainRouteCollection extends RouteCollection
/**
* @var RouteCollection[]
*/
private $routeCollections = array();
private $routeCollections = [];

/**
* @var RouteCollection
Expand Down Expand Up @@ -140,7 +140,7 @@ public function addCollection(RouteCollection $collection)
* @param array $defaults An array of default values
* @param array $requirements An array of requirements
*/
public function addPrefix($prefix, array $defaults = array(), array $requirements = array())
public function addPrefix($prefix, array $defaults = [], array $requirements = [])
{
$this->createInternalCollection();
foreach ($this->routeCollections as $routeCollection) {
Expand All @@ -155,7 +155,7 @@ public function addPrefix($prefix, array $defaults = array(), array $requirement
* @param array $defaults An array of default values
* @param array $requirements An array of requirements
*/
public function setHost($pattern, array $defaults = array(), array $requirements = array())
public function setHost($pattern, array $defaults = [], array $requirements = [])
{
$this->createInternalCollection();
foreach ($this->routeCollections as $routeCollection) {
Expand Down
16 changes: 8 additions & 8 deletions src/ChainRouter.php
Expand Up @@ -42,7 +42,7 @@ class ChainRouter implements ChainRouterInterface, WarmableInterface
*
* @var array
*/
private $routers = array();
private $routers = [];

/**
* @var RouterInterface[] Array of routers, sorted by priority
Expand Down Expand Up @@ -86,11 +86,11 @@ public function add($router, $priority = 0)
throw new \InvalidArgumentException(sprintf('%s is not a valid router.', get_class($router)));
}
if (empty($this->routers[$priority])) {
$this->routers[$priority] = array();
$this->routers[$priority] = [];
}

$this->routers[$priority][] = $router;
$this->sortedRouters = array();
$this->sortedRouters = [];
}

/**
Expand Down Expand Up @@ -127,7 +127,7 @@ protected function sortRouters()
krsort($this->routers);

if (0 === count($this->routers)) {
return array();
return [];
}

return call_user_func_array('array_merge', $this->routers);
Expand Down Expand Up @@ -212,9 +212,9 @@ private function doMatch($pathinfo, Request $request = null)
* Loops through all registered routers and returns a router if one is found.
* It will always return the first route generated.
*/
public function generate($name, $parameters = array(), $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
{
$debug = array();
$debug = [];

foreach ($this->all() as $router) {
// if $router does not announce it is capable of handling
Expand Down Expand Up @@ -266,7 +266,7 @@ private function rebuildRequest($pathinfo)

$uri = $pathinfo;

$server = array();
$server = [];
if ($this->context->getBaseUrl()) {
$uri = $this->context->getBaseUrl().$pathinfo;
$server['SCRIPT_FILENAME'] = $this->context->getBaseUrl();
Expand All @@ -281,7 +281,7 @@ private function rebuildRequest($pathinfo)
}
$uri = $this->context->getScheme().'://'.$host.$uri.'?'.$this->context->getQueryString();

return Request::create($uri, $this->context->getMethod(), $this->context->getParameters(), array(), array(), $server);
return Request::create($uri, $this->context->getMethod(), $this->context->getParameters(), [], [], $server);
}

private function getErrorMessage($name, $router = null, $parameters = null)
Expand Down
5 changes: 3 additions & 2 deletions src/ContentAwareGenerator.php
Expand Up @@ -66,7 +66,7 @@ public function setContentRepository(ContentRepositoryInterface $contentReposito
*
* @throws RouteNotFoundException If there is no such route in the database
*/
public function generate($name, $parameters = array(), $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
{
if ($name instanceof SymfonyRoute) {
$route = $this->getBestLocaleRoute($name, $parameters);
Expand Down Expand Up @@ -122,6 +122,7 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
return $route;
}
$locale = $this->getLocale($parameters);

if (!$this->checkLocaleRequirement($route, $locale)) {
$content = $route->getContent();
if ($content instanceof RouteReferrersReadInterface) {
Expand Down Expand Up @@ -284,7 +285,7 @@ public function supports($name)
/**
* {@inheritdoc}
*/
public function getRouteDebugMessage($name, array $parameters = array())
public function getRouteDebugMessage($name, array $parameters = [])
{
if (!$name && array_key_exists('content_id', $parameters)) {
return 'Content id '.$parameters['content_id'];
Expand Down
Expand Up @@ -53,7 +53,7 @@ public function process(ContainerBuilder $container)

foreach ($container->findTaggedServiceIds($this->enhancerTag) as $id => $attributes) {
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$router->addMethodCall('addRouteEnhancer', array(new Reference($id), $priority));
$router->addMethodCall('addRouteEnhancer', [new Reference($id), $priority]);
}
}
}
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/RegisterRoutersPass.php
Expand Up @@ -48,7 +48,7 @@ public function process(ContainerBuilder $container)
foreach ($container->findTaggedServiceIds($this->routerTag) as $id => $attributes) {
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;

$definition->addMethodCall('add', array(new Reference($id), $priority));
$definition->addMethodCall('add', [new Reference($id), $priority]);
}
}
}
14 changes: 7 additions & 7 deletions src/DynamicRouter.php
Expand Up @@ -56,14 +56,14 @@ class DynamicRouter implements RouterInterface, RequestMatcherInterface, Chained
/**
* @var RouteEnhancerInterface[][]
*/
protected $enhancers = array();
protected $enhancers = [];

/**
* Cached sorted list of enhancers.
*
* @var RouteEnhancerInterface[]
*/
protected $sortedEnhancers = array();
protected $sortedEnhancers = [];

/**
* The regexp pattern that needs to be matched before a dynamic lookup is
Expand Down Expand Up @@ -176,7 +176,7 @@ public function getGenerator()
*
* @api
*/
public function generate($name, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
if ($this->eventDispatcher) {
$event = new RouterGenerateEvent($name, $parameters, $referenceType);
Expand Down Expand Up @@ -316,11 +316,11 @@ protected function applyRouteEnhancers($defaults, Request $request)
public function addRouteEnhancer(RouteEnhancerInterface $enhancer, $priority = 0)
{
if (empty($this->enhancers[$priority])) {
$this->enhancers[$priority] = array();
$this->enhancers[$priority] = [];
}

$this->enhancers[$priority][] = $enhancer;
$this->sortedEnhancers = array();
$this->sortedEnhancers = [];

return $this;
}
Expand Down Expand Up @@ -351,7 +351,7 @@ protected function sortRouteEnhancers()
krsort($this->enhancers);

if (0 === count($this->enhancers)) {
return array();
return [];
}

return call_user_func_array('array_merge', $this->enhancers);
Expand Down Expand Up @@ -386,7 +386,7 @@ public function getContext()
*
* Forwards to the generator.
*/
public function getRouteDebugMessage($name, array $parameters = array())
public function getRouteDebugMessage($name, array $parameters = [])
{
if ($this->generator instanceof VersatileGeneratorInterface) {
return $this->generator->getRouteDebugMessage($name, $parameters);
Expand Down
8 changes: 4 additions & 4 deletions src/NestedMatcher/NestedMatcher.php
Expand Up @@ -51,14 +51,14 @@ class NestedMatcher implements RequestMatcherInterface
*
* @var RouteFilterInterface[]
*/
protected $filters = array();
protected $filters = [];

/**
* Array of RouteFilterInterface objects, sorted.
*
* @var RouteFilterInterface[]
*/
protected $sortedFilters = array();
protected $sortedFilters = [];

/**
* Constructs a new NestedMatcher.
Expand Down Expand Up @@ -109,11 +109,11 @@ public function setRouteProvider(RouteProviderInterface $provider)
public function addRouteFilter(RouteFilterInterface $filter, $priority = 0)
{
if (empty($this->filters[$priority])) {
$this->filters[$priority] = array();
$this->filters[$priority] = [];
}

$this->filters[$priority][] = $filter;
$this->sortedFilters = array();
$this->sortedFilters = [];

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PagedRouteCollection.php
Expand Up @@ -62,7 +62,7 @@ protected function loadNextElements($offset)
// If the last batch was smaller than the batch size, this means there
// are no more routes available.
if (isset($this->currentRoutes) && count($this->currentRoutes) < $this->routesBatchSize) {
$this->currentRoutes = array();
$this->currentRoutes = [];
} else {
$this->currentRoutes = $this->provider->getRoutesPaged($offset, $this->routesBatchSize);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ProviderBasedGenerator.php
Expand Up @@ -45,7 +45,7 @@ public function __construct(RouteProviderInterface $provider, LoggerInterface $l
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
{
if ($name instanceof SymfonyRoute) {
$route = $name;
Expand Down Expand Up @@ -75,7 +75,7 @@ public function supports($name)
/**
* {@inheritdoc}
*/
public function getRouteDebugMessage($name, array $parameters = array())
public function getRouteDebugMessage($name, array $parameters = [])
{
if (is_scalar($name)) {
return $name;
Expand Down
23 changes: 0 additions & 23 deletions src/Test/CmfUnitTestCase.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/VersatileGeneratorInterface.php
Expand Up @@ -42,5 +42,5 @@ public function supports($name);
*
* @return string
*/
public function getRouteDebugMessage($name, array $parameters = array());
public function getRouteDebugMessage($name, array $parameters = []);
}

0 comments on commit 2f13903

Please sign in to comment.