diff --git a/src/Symfony/Bridge/PhpUnit/ClassExistsMock.php b/src/Symfony/Bridge/PhpUnit/ClassExistsMock.php index 23869c033d..e8ca4ac940 100644 --- a/src/Symfony/Bridge/PhpUnit/ClassExistsMock.php +++ b/src/Symfony/Bridge/PhpUnit/ClassExistsMock.php @@ -16,7 +16,7 @@ namespace Symfony\Bridge\PhpUnit; */ class ClassExistsMock { - private static $classes = array(); + private static $classes = []; /** * Configures the classes to be checked upon existence. @@ -47,7 +47,7 @@ class ClassExistsMock { $self = \get_called_class(); - $mockedNs = array(substr($class, 0, strrpos($class, '\\'))); + $mockedNs = [substr($class, 0, strrpos($class, '\\'))]; if (0 < strpos($class, '\\Tests\\')) { $ns = str_replace('\\Tests\\', '\\', $class); $mockedNs[] = substr($ns, 0, strrpos($ns, '\\')); @@ -55,7 +55,7 @@ class ClassExistsMock $mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6); } foreach ($mockedNs as $ns) { - foreach (array('class', 'interface', 'trait') as $type) { + foreach (['class', 'interface', 'trait'] as $type) { if (\function_exists($ns.'\\'.$type.'_exists')) { continue; } diff --git a/src/Symfony/Bridge/PhpUnit/Tests/ClassExistsMockTest.php b/src/Symfony/Bridge/PhpUnit/Tests/ClassExistsMockTest.php index 30d8edf95f..002d313a6f 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/ClassExistsMockTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/ClassExistsMockTest.php @@ -23,14 +23,14 @@ class ClassExistsMockTest extends TestCase protected function setUp() { - ClassExistsMock::withMockedClasses(array( + ClassExistsMock::withMockedClasses([ ExistingClass::class => false, 'NonExistingClass' => true, ExistingInterface::class => false, 'NonExistingInterface' => true, ExistingTrait::class => false, 'NonExistingTrait' => true, - )); + ]); } public function testClassExists() diff --git a/src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php index 5f98efab0d..e3a724cd24 100644 --- a/src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php @@ -60,7 +60,7 @@ class Configuration implements ConfigurationInterface ->enumNode('theme') ->info('Changes the color of the dump() output when rendered directly on the templating. "dark" (default) or "light"') ->example('dark') - ->values(array('dark', 'light')) + ->values(['dark', 'light']) ->defaultValue('dark') ->end() ->end() diff --git a/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php b/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php index da07d97051..9c098a0996 100644 --- a/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php +++ b/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php @@ -45,7 +45,7 @@ class DebugExtension extends Extension if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) { $container->getDefinition('var_dumper.html_dumper') - ->addMethodCall('setTheme', array($config['theme'])); + ->addMethodCall('setTheme', [$config['theme']]); } if (null === $config['dump_destination']) { @@ -79,9 +79,9 @@ class DebugExtension extends Extension if (method_exists(CliDumper::class, 'setDisplayOptions')) { $container->getDefinition('var_dumper.cli_dumper') - ->addMethodCall('setDisplayOptions', array(array( + ->addMethodCall('setDisplayOptions', [[ 'fileLinkFormat' => new Reference('debug.file_link_formatter', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE), - ))) + ]]) ; } } diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 0d1382a5f0..461f5f5e54 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -31,7 +31,7 @@ abstract class Client { protected $history; protected $cookieJar; - protected $server = array(); + protected $server = []; protected $internalRequest; protected $request; protected $internalResponse; @@ -44,7 +44,7 @@ abstract class Client private $maxRedirects = -1; private $redirectCount = 0; - private $redirects = array(); + private $redirects = []; private $isMainRequest = true; /** @@ -52,7 +52,7 @@ abstract class Client * @param History $history A History instance to store the browser history * @param CookieJar $cookieJar A CookieJar instance to store the cookies */ - public function __construct(array $server = array(), History $history = null, CookieJar $cookieJar = null) + public function __construct(array $server = [], History $history = null, CookieJar $cookieJar = null) { $this->setServerParameters($server); $this->history = $history ?: new History(); @@ -131,9 +131,9 @@ abstract class Client */ public function setServerParameters(array $server) { - $this->server = array_merge(array( + $this->server = array_merge([ 'HTTP_USER_AGENT' => 'Symfony BrowserKit', - ), $server); + ], $server); } /** @@ -160,7 +160,7 @@ abstract class Client return isset($this->server[$key]) ? $this->server[$key] : $default; } - public function xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true): Crawler + public function xmlHttpRequest(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true): Crawler { $this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest'); @@ -313,14 +313,14 @@ abstract class Client * * @return Crawler */ - public function submit(Form $form, array $values = array()/*, array $serverParameters = array()*/) + public function submit(Form $form, array $values = []/*, array $serverParameters = array()*/) { if (\func_num_args() < 3 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) { @trigger_error(sprintf('The "%s()" method will have a new "array $serverParameters = array()" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED); } $form->setValues($values); - $serverParameters = 2 < \func_num_args() ? func_get_arg(2) : array(); + $serverParameters = 2 < \func_num_args() ? func_get_arg(2) : []; return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles(), $serverParameters); } @@ -334,7 +334,7 @@ abstract class Client * @param string $method The HTTP method used to submit the form * @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include a HTTP_ prefix as PHP does) */ - public function submitForm(string $button, array $fieldValues = array(), string $method = 'POST', array $serverParameters = array()): Crawler + public function submitForm(string $button, array $fieldValues = [], string $method = 'POST', array $serverParameters = []): Crawler { if (null === $this->crawler) { throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__)); @@ -343,7 +343,7 @@ abstract class Client $buttonNode = $this->crawler->selectButton($button); $form = $buttonNode->form($fieldValues, $method); - return $this->submit($form, array(), $serverParameters); + return $this->submit($form, [], $serverParameters); } /** @@ -359,7 +359,7 @@ abstract class Client * * @return Crawler */ - public function request(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true) + public function request(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true) { if ($this->isMainRequest) { $this->redirectCount = 0; @@ -455,7 +455,7 @@ abstract class Client if (file_exists($deprecationsFile)) { $deprecations = file_get_contents($deprecationsFile); unlink($deprecationsFile); - foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) { + foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) { if ($deprecation[0]) { @trigger_error($deprecation[1], E_USER_DEPRECATED); } else { @@ -599,9 +599,9 @@ abstract class Client $request = $this->internalRequest; - if (\in_array($this->internalResponse->getStatusCode(), array(301, 302, 303))) { + if (\in_array($this->internalResponse->getStatusCode(), [301, 302, 303])) { $method = 'GET'; - $files = array(); + $files = []; $content = null; } else { $method = $request->getMethod(); @@ -611,7 +611,7 @@ abstract class Client if ('GET' === strtoupper($method)) { // Don't forward parameters for GET request as it should reach the redirection URI - $parameters = array(); + $parameters = []; } else { $parameters = $request->getParameters(); } @@ -634,7 +634,7 @@ abstract class Client private function getMetaRefreshUrl(): ?string { $metaRefresh = $this->getCrawler()->filter('head meta[http-equiv="refresh"]'); - foreach ($metaRefresh->extract(array('content')) as $content) { + foreach ($metaRefresh->extract(['content']) as $content) { if (preg_match('/^\s*0\s*;\s*URL\s*=\s*(?|\'([^\']++)|"([^"]++)|([^\'"].*))/i', $content, $m)) { return str_replace("\t\r\n", '', rtrim($m[1])); } diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php index 4c92655998..6a181f8ff6 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php @@ -20,40 +20,40 @@ use Symfony\Component\Console\Exception\InvalidArgumentException; */ class OutputFormatterStyle implements OutputFormatterStyleInterface { - private static $availableForegroundColors = array( - 'black' => array('set' => 30, 'unset' => 39), - 'red' => array('set' => 31, 'unset' => 39), - 'green' => array('set' => 32, 'unset' => 39), - 'yellow' => array('set' => 33, 'unset' => 39), - 'blue' => array('set' => 34, 'unset' => 39), - 'magenta' => array('set' => 35, 'unset' => 39), - 'cyan' => array('set' => 36, 'unset' => 39), - 'white' => array('set' => 37, 'unset' => 39), - 'default' => array('set' => 39, 'unset' => 39), - ); - private static $availableBackgroundColors = array( - 'black' => array('set' => 40, 'unset' => 49), - 'red' => array('set' => 41, 'unset' => 49), - 'green' => array('set' => 42, 'unset' => 49), - 'yellow' => array('set' => 43, 'unset' => 49), - 'blue' => array('set' => 44, 'unset' => 49), - 'magenta' => array('set' => 45, 'unset' => 49), - 'cyan' => array('set' => 46, 'unset' => 49), - 'white' => array('set' => 47, 'unset' => 49), - 'default' => array('set' => 49, 'unset' => 49), - ); - private static $availableOptions = array( - 'bold' => array('set' => 1, 'unset' => 22), - 'underscore' => array('set' => 4, 'unset' => 24), - 'blink' => array('set' => 5, 'unset' => 25), - 'reverse' => array('set' => 7, 'unset' => 27), - 'conceal' => array('set' => 8, 'unset' => 28), - ); + private static $availableForegroundColors = [ + 'black' => ['set' => 30, 'unset' => 39], + 'red' => ['set' => 31, 'unset' => 39], + 'green' => ['set' => 32, 'unset' => 39], + 'yellow' => ['set' => 33, 'unset' => 39], + 'blue' => ['set' => 34, 'unset' => 39], + 'magenta' => ['set' => 35, 'unset' => 39], + 'cyan' => ['set' => 36, 'unset' => 39], + 'white' => ['set' => 37, 'unset' => 39], + 'default' => ['set' => 39, 'unset' => 39], + ]; + private static $availableBackgroundColors = [ + 'black' => ['set' => 40, 'unset' => 49], + 'red' => ['set' => 41, 'unset' => 49], + 'green' => ['set' => 42, 'unset' => 49], + 'yellow' => ['set' => 43, 'unset' => 49], + 'blue' => ['set' => 44, 'unset' => 49], + 'magenta' => ['set' => 45, 'unset' => 49], + 'cyan' => ['set' => 46, 'unset' => 49], + 'white' => ['set' => 47, 'unset' => 49], + 'default' => ['set' => 49, 'unset' => 49], + ]; + private static $availableOptions = [ + 'bold' => ['set' => 1, 'unset' => 22], + 'underscore' => ['set' => 4, 'unset' => 24], + 'blink' => ['set' => 5, 'unset' => 25], + 'reverse' => ['set' => 7, 'unset' => 27], + 'conceal' => ['set' => 8, 'unset' => 28], + ]; private $foreground; private $background; private $href; - private $options = array(); + private $options = []; private $handlesHrefGracefully; /** @@ -63,7 +63,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * @param string|null $background The style background color name * @param array $options The style options */ - public function __construct(string $foreground = null, string $background = null, array $options = array()) + public function __construct(string $foreground = null, string $background = null, array $options = []) { if (null !== $foreground) { $this->setForeground($foreground); @@ -167,7 +167,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface */ public function setOptions(array $options) { - $this->options = array(); + $this->options = []; foreach ($options as $option) { $this->setOption($option); @@ -183,8 +183,8 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface */ public function apply($text) { - $setCodes = array(); - $unsetCodes = array(); + $setCodes = []; + $unsetCodes = []; if (null === $this->handlesHrefGracefully) { $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR'); diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php index 0d81207392..ced7634186 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php @@ -256,15 +256,15 @@ class OutputFormatterTest extends TestCase public function provideDecoratedAndNonDecoratedOutput() { - return array( - array('some error', 'some error', "\033[37;41msome error\033[39;49m"), - array('some info', 'some info', "\033[32msome info\033[39m"), - array('some comment', 'some comment', "\033[33msome comment\033[39m"), - array('some question', 'some question', "\033[30;46msome question\033[39;49m"), - array('some text with inline style', 'some text with inline style', "\033[31msome text with inline style\033[39m"), - array('some URL', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"), - array('some URL', 'some URL', 'some URL', 'JetBrains-JediTerm'), - ); + return [ + ['some error', 'some error', "\033[37;41msome error\033[39;49m"], + ['some info', 'some info', "\033[32msome info\033[39m"], + ['some comment', 'some comment', "\033[33msome comment\033[39m"], + ['some question', 'some question', "\033[30;46msome question\033[39;49m"], + ['some text with inline style', 'some text with inline style', "\033[31msome text with inline style\033[39m"], + ['some URL', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"], + ['some URL', 'some URL', 'some URL', 'JetBrains-JediTerm'], + ]; } public function testContentWithLineBreaks() diff --git a/src/Symfony/Component/Debug/DebugClassLoader.php b/src/Symfony/Component/Debug/DebugClassLoader.php index 492f085985..efc52a2fd6 100644 --- a/src/Symfony/Component/Debug/DebugClassLoader.php +++ b/src/Symfony/Component/Debug/DebugClassLoader.php @@ -29,17 +29,17 @@ class DebugClassLoader { private $classLoader; private $isFinder; - private $loaded = array(); + private $loaded = []; private static $caseCheck; - private static $checkedClasses = array(); - private static $final = array(); - private static $finalMethods = array(); - private static $deprecated = array(); - private static $internal = array(); - private static $internalMethods = array(); - private static $annotatedParameters = array(); - private static $darwinCache = array('/' => array('/', array())); - private static $method = array(); + private static $checkedClasses = []; + private static $final = []; + private static $finalMethods = []; + private static $deprecated = []; + private static $internal = []; + private static $internalMethods = []; + private static $annotatedParameters = []; + private static $darwinCache = ['/' => ['/', []]]; + private static $method = []; public function __construct(callable $classLoader) { @@ -99,7 +99,7 @@ class DebugClassLoader foreach ($functions as $function) { if (!\is_array($function) || !$function[0] instanceof self) { - $function = array(new static($function), 'loadClass'); + $function = [new static($function), 'loadClass']; } spl_autoload_register($function); @@ -220,7 +220,7 @@ class DebugClassLoader public function checkAnnotations(\ReflectionClass $refl, $class) { - $deprecations = array(); + $deprecations = []; // Don't trigger deprecations for classes in the same vendor if (2 > $len = 1 + (\strpos($class, '\\') ?: \strpos($class, '_'))) { @@ -232,7 +232,7 @@ class DebugClassLoader // Detect annotations on the class if (false !== $doc = $refl->getDocComment()) { - foreach (array('final', 'deprecated', 'internal') as $annotation) { + foreach (['final', 'deprecated', 'internal'] as $annotation) { if (false !== \strpos($doc, $annotation) && preg_match('#\n \* @'.$annotation.'(?:( .+?)\.?)?\r?\n \*(?: @|/$)#s', $doc, $notice)) { self::${$annotation}[$class] = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : ''; } @@ -252,7 +252,7 @@ class DebugClassLoader $description .= '.'; } } - self::$method[$class][] = array($class, $name, $static, $description); + self::$method[$class][] = [$class, $name, $static, $description]; } } } @@ -314,11 +314,11 @@ class DebugClassLoader } // Inherit @final, @internal and @param annotations for methods - self::$finalMethods[$class] = array(); - self::$internalMethods[$class] = array(); - self::$annotatedParameters[$class] = array(); + self::$finalMethods[$class] = []; + self::$internalMethods[$class] = []; + self::$annotatedParameters[$class] = []; foreach ($parentAndOwnInterfaces as $use) { - foreach (array('finalMethods', 'internalMethods', 'annotatedParameters') as $property) { + foreach (['finalMethods', 'internalMethods', 'annotatedParameters'] as $property) { if (isset(self::${$property}[$use])) { self::${$property}[$class] = self::${$property}[$class] ? self::${$property}[$use] + self::${$property}[$class] : self::${$property}[$use]; } @@ -346,7 +346,7 @@ class DebugClassLoader $doc = $method->getDocComment(); if (isset(self::$annotatedParameters[$class][$method->name])) { - $definedParameters = array(); + $definedParameters = []; foreach ($method->getParameters() as $parameter) { $definedParameters[$parameter->name] = true; } @@ -364,10 +364,10 @@ class DebugClassLoader $finalOrInternal = false; - foreach (array('final', 'internal') as $annotation) { + foreach (['final', 'internal'] as $annotation) { if (false !== \strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s', $doc, $notice)) { $message = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : ''; - self::${$annotation.'Methods'}[$class][$method->name] = array($class, $message); + self::${$annotation.'Methods'}[$class][$method->name] = [$class, $message]; $finalOrInternal = true; } } @@ -379,7 +379,7 @@ class DebugClassLoader continue; } if (!isset(self::$annotatedParameters[$class][$method->name])) { - $definedParameters = array(); + $definedParameters = []; foreach ($method->getParameters() as $parameter) { $definedParameters[$parameter->name] = true; } @@ -425,7 +425,7 @@ class DebugClassLoader if (0 === substr_compare($real, $tail, -$tailLen, $tailLen, true) && 0 !== substr_compare($real, $tail, -$tailLen, $tailLen, false) ) { - return array(substr($tail, -$tailLen + 1), substr($real, -$tailLen + 1), substr($real, 0, -$tailLen + 1)); + return [substr($tail, -$tailLen + 1), substr($real, -$tailLen + 1), substr($real, 0, -$tailLen + 1)]; } } @@ -455,7 +455,7 @@ class DebugClassLoader $k = $kDir; $i = \strlen($dir) - 1; while (!isset(self::$darwinCache[$k])) { - self::$darwinCache[$k] = array($dir, array()); + self::$darwinCache[$k] = [$dir, []]; self::$darwinCache[$dir] = &self::$darwinCache[$k]; while ('/' !== $dir[--$i]) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index bccb74538e..e01f5bf088 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -62,7 +62,7 @@ class PhpDumper extends Dumper private $variableCount; private $inlinedDefinitions; private $serviceCalls; - private $reservedVariables = array('instance', 'class', 'this'); + private $reservedVariables = ['instance', 'class', 'this']; private $expressionLanguage; private $targetDirRegex; private $targetDirMaxMatches; @@ -73,14 +73,14 @@ class PhpDumper extends Dumper private $asFiles; private $hotPathTag; private $inlineRequires; - private $inlinedRequires = array(); - private $circularReferences = array(); - private $singleUsePrivateIds = array(); + private $inlinedRequires = []; + private $circularReferences = []; + private $singleUsePrivateIds = []; private $addThrow = false; private $addGetService = false; - private $locatedIds = array(); + private $locatedIds = []; private $serviceLocatorTag; - private $exportedVariables = array(); + private $exportedVariables = []; /** * @var ProxyDumper @@ -121,13 +121,13 @@ class PhpDumper extends Dumper * * @throws EnvParameterException When an env var exists but has not been dumped */ - public function dump(array $options = array()) + public function dump(array $options = []) { - $this->locatedIds = array(); + $this->locatedIds = []; $this->targetDirRegex = null; - $this->inlinedRequires = array(); - $this->exportedVariables = array(); - $options = array_merge(array( + $this->inlinedRequires = []; + $this->exportedVariables = []; + $options = array_merge([ 'class' => 'ProjectServiceContainer', 'base_class' => 'Container', 'namespace' => '', @@ -137,7 +137,7 @@ class PhpDumper extends Dumper 'inline_class_loader_parameter' => 'container.dumper.inline_class_loader', 'service_locator_tag' => 'container.service_locator', 'build_time' => time(), - ), $options); + ], $options); $this->addThrow = $this->addGetService = false; $this->namespace = $options['namespace']; @@ -171,9 +171,9 @@ class PhpDumper extends Dumper } (new AnalyzeServiceReferencesPass(false, !$this->getProxyDumper() instanceof NullDumper))->process($this->container); - $checkedNodes = array(); - $this->circularReferences = array(); - $this->singleUsePrivateIds = array(); + $checkedNodes = []; + $this->circularReferences = []; + $this->singleUsePrivateIds = []; foreach ($this->container->getCompiler()->getServiceReferenceGraph()->getNodes() as $id => $node) { if (!$node->getValue() instanceof Definition) { continue; @@ -186,7 +186,7 @@ class PhpDumper extends Dumper } } $this->container->getCompiler()->getServiceReferenceGraph()->clear(); - $checkedNodes = array(); + $checkedNodes = []; $this->docStar = $options['debug'] ? '*' : ''; @@ -240,7 +240,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; // This file has been auto-generated by the Symfony Dependency Injection Component for internal use. EOF; - $files = array(); + $files = []; $ids = $this->container->getRemovedIds(); foreach ($this->container->getDefinitions() as $id => $definition) { @@ -265,7 +265,7 @@ EOF; } $files[$options['class'].'.php'] = $code.$this->endClass(); $hash = ucfirst(strtr(ContainerBuilder::hash($files), '._', 'xx')); - $code = array(); + $code = []; foreach ($files as $file => $c) { $code["Container{$hash}/{$file}"] = $c; @@ -308,12 +308,12 @@ EOF; } $this->targetDirRegex = null; - $this->inlinedRequires = array(); - $this->circularReferences = array(); - $this->locatedIds = array(); - $this->exportedVariables = array(); + $this->inlinedRequires = []; + $this->circularReferences = []; + $this->locatedIds = []; + $this->exportedVariables = []; - $unusedEnvs = array(); + $unusedEnvs = []; foreach ($this->container->getEnvCounters() as $env => $use) { if (!$use) { $unusedEnvs[] = $env; @@ -338,7 +338,7 @@ EOF; return $this->proxyDumper; } - private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = array()) + private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = []) { $checkedNodes[$sourceId] = true; $currentPath[$sourceId] = $sourceId; @@ -367,7 +367,7 @@ EOF; unset($currentPath[$sourceId]); } - private function connectCircularReferences($sourceId, &$currentPath, &$subPath = array()) + private function connectCircularReferences($sourceId, &$currentPath, &$subPath = []) { $subPath[$sourceId] = $sourceId; $currentPath[$sourceId] = $sourceId; @@ -423,7 +423,7 @@ EOF; private function generateProxyClasses() { - $alreadyGenerated = array(); + $alreadyGenerated = []; $definitions = $this->container->getDefinitions(); $strip = '' === $this->docStar && method_exists('Symfony\Component\HttpKernel\Kernel', 'stripComments'); $proxyDumper = $this->getProxyDumper(); @@ -454,7 +454,7 @@ EOF; $code = ''; if ($this->inlineRequires && !$this->isHotPath($definition)) { - $lineage = array(); + $lineage = []; foreach ($this->inlinedDefinitions as $def) { if (!$def->isDeprecated() && \is_string($class = \is_array($factory = $def->getFactory()) && \is_string($factory[0]) ? $factory[0] : $def->getClass())) { $this->collectLineage($class, $lineage); @@ -566,7 +566,7 @@ EOF; { $calls = ''; foreach ($definition->getMethodCalls() as $call) { - $arguments = array(); + $arguments = []; foreach ($call[1] as $value) { $arguments[] = $this->dumpValue($value); } @@ -619,11 +619,11 @@ EOF; private function addService(string $id, Definition $definition): array { $this->definitionVariables = new \SplObjectStorage(); - $this->referenceVariables = array(); + $this->referenceVariables = []; $this->variableCount = 0; $this->referenceVariables[$id] = new Variable('instance'); - $return = array(); + $return = []; if ($class = $definition->getClass()) { $class = $class instanceof Parameter ? '%'.$class.'%' : $this->container->resolveEnvPlaceholders($class); @@ -680,8 +680,8 @@ EOF; EOF; } - $this->serviceCalls = array(); - $this->inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition), null, $this->serviceCalls); + $this->serviceCalls = []; + $this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls); $code .= $this->addServiceInclude($id, $definition); @@ -705,7 +705,7 @@ EOF; $this->definitionVariables = $this->inlinedDefinitions = null; $this->referenceVariables = $this->serviceCalls = null; - return array($file, $code); + return [$file, $code]; } private function addInlineVariables(string $id, Definition $definition, array $arguments, bool $forConstructor): string @@ -782,11 +782,11 @@ EOTXT return ''; } - $arguments = array($inlineDef->getArguments(), $inlineDef->getFactory()); + $arguments = [$inlineDef->getArguments(), $inlineDef->getFactory()]; $code = $this->addInlineVariables($id, $definition, $arguments, $forConstructor); - if ($arguments = array_filter(array($inlineDef->getProperties(), $inlineDef->getMethodCalls(), $inlineDef->getConfigurator()))) { + if ($arguments = array_filter([$inlineDef->getProperties(), $inlineDef->getMethodCalls(), $inlineDef->getConfigurator()])) { $isSimpleInstance = false; } elseif ($definition !== $inlineDef && 2 > $this->inlinedDefinitions[$inlineDef]) { return $code; @@ -855,9 +855,9 @@ EOTXT if (!$definition->isShared()) { $i = strpos($code, "\n\ninclude_once "); if (false !== $i && false !== $i = strpos($code, "\n\n", 2 + $i)) { - $code = array(substr($code, 0, 2 + $i), substr($code, 2 + $i)); + $code = [substr($code, 0, 2 + $i), substr($code, 2 + $i)]; } else { - $code = array("\n", $code); + $code = ["\n", $code]; } $code[1] = implode("\n", array_map(function ($line) { return $line ? ' '.$line : $line; }, explode("\n", $code[1]))); $factory = sprintf('$this->factories%s[\'%s\']', $definition->isPublic() ? '' : "['service_container']", $id); @@ -875,7 +875,7 @@ EOTXT $tail = $return ? ";\n" : ''; if (BaseServiceLocator::class === $definition->getClass() && $definition->hasTag($this->serviceLocatorTag)) { - $arguments = array(); + $arguments = []; foreach ($definition->getArgument(0) as $k => $argument) { $arguments[$k] = $argument->getValues()[0]; } @@ -883,7 +883,7 @@ EOTXT return $return.$this->dumpValue(new ServiceLocatorArgument($arguments)).$tail; } - $arguments = array(); + $arguments = []; foreach ($definition->getArguments() as $value) { $arguments[] = $this->dumpValue($value); } @@ -1157,11 +1157,11 @@ EOF; return ''; } - $lineage = array(); + $lineage = []; foreach ($this->container->findTaggedServiceIds($this->hotPathTag) as $id => $tags) { $definition = $this->container->getDefinition($id); - $inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition)); + $inlinedDefinitions = $this->getDefinitionsFromArguments([$definition]); foreach ($inlinedDefinitions as $def) { if (\is_string($class = \is_array($factory = $def->getFactory()) && \is_string($factory[0]) ? $factory[0] : $def->getClass())) { @@ -1188,14 +1188,14 @@ EOF; return ''; } - $php = array(); - $dynamicPhp = array(); + $php = []; + $dynamicPhp = []; foreach ($this->container->getParameterBag()->all() as $key => $value) { if ($key !== $resolvedKey = $this->container->resolveEnvPlaceholders($key)) { throw new InvalidArgumentException(sprintf('Parameter name cannot use env parameters: %s.', $resolvedKey)); } - $export = $this->exportParameters(array($value)); + $export = $this->exportParameters([$value]); $export = explode('0 => ', substr(rtrim($export, " )\n"), 7, -1), 2); if (preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $export[1])) { @@ -1317,7 +1317,7 @@ EOF; */ private function exportParameters(array $parameters, string $path = '', int $indent = 12): string { - $php = array(); + $php = []; foreach ($parameters as $key => $value) { if (\is_array($value)) { $value = $this->exportParameters($value, $path.'/'.$key, $indent + 4); @@ -1375,7 +1375,7 @@ EOF; private function getServiceConditionals($value): string { - $conditions = array(); + $conditions = []; foreach (ContainerBuilder::getInitializedConditionals($value) as $service) { if (!$this->container->hasDefinition($service)) { return 'false'; @@ -1397,7 +1397,7 @@ EOF; return implode(' && ', $conditions); } - private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions = null, array &$calls = array()): \SplObjectStorage + private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions = null, array &$calls = []): \SplObjectStorage { if (null === $definitions) { $definitions = new \SplObjectStorage(); @@ -1410,7 +1410,7 @@ EOF; $id = (string) $argument; if (!isset($calls[$id])) { - $calls[$id] = array(0, $argument->getInvalidBehavior()); + $calls[$id] = [0, $argument->getInvalidBehavior()]; } else { $calls[$id][1] = min($calls[$id][1], $argument->getInvalidBehavior()); } @@ -1422,7 +1422,7 @@ EOF; $definitions[$argument] = 1 + $definitions[$argument]; } else { $definitions[$argument] = 1; - $arguments = array($argument->getArguments(), $argument->getFactory(), $argument->getProperties(), $argument->getMethodCalls(), $argument->getConfigurator()); + $arguments = [$argument->getArguments(), $argument->getFactory(), $argument->getProperties(), $argument->getMethodCalls(), $argument->getConfigurator()]; $this->getDefinitionsFromArguments($arguments, $definitions, $calls); } } @@ -1439,14 +1439,14 @@ EOF; if ($value && $interpolate && false !== $param = array_search($value, $this->container->getParameterBag()->all(), true)) { return $this->dumpValue("%$param%"); } - $code = array(); + $code = []; foreach ($value as $k => $v) { $code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate)); } return sprintf('array(%s)', implode(', ', $code)); } elseif ($value instanceof ArgumentInterface) { - $scope = array($this->definitionVariables, $this->referenceVariables); + $scope = [$this->definitionVariables, $this->referenceVariables]; $this->definitionVariables = $this->referenceVariables = null; try { @@ -1465,14 +1465,14 @@ EOF; } if ($value instanceof IteratorArgument) { - $operands = array(0); - $code = array(); + $operands = [0]; + $code = []; $code[] = 'new RewindableGenerator(function () {'; if (!$values = $value->getValues()) { $code[] = ' return new \EmptyIterator();'; } else { - $countCode = array(); + $countCode = []; $countCode[] = 'function () {'; foreach ($values as $k => $v) { @@ -1548,7 +1548,7 @@ EOF; return $this->getServiceCall($id, $value); } elseif ($value instanceof Expression) { - return $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container')); + return $this->getExpressionLanguage()->compile((string) $value, ['this' => 'container']); } elseif ($value instanceof Parameter) { return $this->dumpParameter($value); } elseif (true === $interpolate && \is_string($value)) { @@ -1670,8 +1670,8 @@ EOF; */ private function initializeMethodNamesMap(string $class) { - $this->serviceIdToMethodNameMap = array(); - $this->usedMethodNames = array(); + $this->serviceIdToMethodNameMap = []; + $this->usedMethodNames = []; if ($reflectionClass = $this->container->getReflectionClass($class)) { foreach ($reflectionClass->getMethods() as $method) { @@ -1776,7 +1776,7 @@ EOF; if ($node->getValue()->isPublic()) { return false; } - $ids = array(); + $ids = []; foreach ($node->getInEdges() as $edge) { if (!$value = $edge->getSourceNode()->getValue()) { continue; diff --git a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php index fea1ffe8c9..1b71924d8a 100644 --- a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php +++ b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php @@ -31,7 +31,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface */ public static function getProvidedTypes() { - return array( + return [ 'base64' => 'string', 'bool' => 'bool', 'const' => 'bool|int|float|string|array', @@ -45,7 +45,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface 'default' => 'bool|int|float|string|array', 'string' => 'string', 'trim' => 'string', - ); + ]; } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index d7da25a602..c6c71f7c26 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -902,7 +902,7 @@ class AutowirePassTest extends TestCase (new AutowirePass())->process($container); - $this->assertSame(array('Cannot autowire service "some_locator": it has type "Symfony\Component\DependencyInjection\Tests\Compiler\MissingClass" but this class was not found.'), $container->getDefinition('.errored.some_locator.'.MissingClass::class)->getErrors()); + $this->assertSame(['Cannot autowire service "some_locator": it has type "Symfony\Component\DependencyInjection\Tests\Compiler\MissingClass" but this class was not found.'], $container->getDefinition('.errored.some_locator.'.MissingClass::class)->getErrors()); } public function testNamedArgumentAliasResolveCollisions() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php index bdc05146e4..f376165dfc 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php @@ -28,22 +28,22 @@ class RegisterEnvVarProcessorsPassTest extends TestCase $this->assertTrue($container->has('container.env_var_processors_locator')); $this->assertInstanceOf(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo')); - $expected = array( - 'foo' => array('string'), - 'base64' => array('string'), - 'bool' => array('bool'), - 'const' => array('bool', 'int', 'float', 'string', 'array'), - 'csv' => array('array'), - 'file' => array('string'), - 'float' => array('float'), - 'int' => array('int'), - 'json' => array('array'), - 'key' => array('bool', 'int', 'float', 'string', 'array'), - 'resolve' => array('string'), - 'default' => array('bool', 'int', 'float', 'string', 'array'), - 'string' => array('string'), - 'trim' => array('string'), - ); + $expected = [ + 'foo' => ['string'], + 'base64' => ['string'], + 'bool' => ['bool'], + 'const' => ['bool', 'int', 'float', 'string', 'array'], + 'csv' => ['array'], + 'file' => ['string'], + 'float' => ['float'], + 'int' => ['int'], + 'json' => ['array'], + 'key' => ['bool', 'int', 'float', 'string', 'array'], + 'resolve' => ['string'], + 'default' => ['bool', 'int', 'float', 'string', 'array'], + 'string' => ['string'], + 'trim' => ['string'], + ]; $this->assertSame($expected, $container->getParameterBag()->getProvidedTypes()); } @@ -79,7 +79,7 @@ class SimpleProcessor implements EnvVarProcessorInterface public static function getProvidedTypes() { - return array('foo' => 'string'); + return ['foo' => 'string']; } } @@ -87,6 +87,6 @@ class BadProcessor extends SimpleProcessor { public static function getProvidedTypes() { - return array('foo' => 'string|foo'); + return ['foo' => 'string|foo']; } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php index a3ebb1b3dd..22950f3455 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php @@ -221,9 +221,9 @@ class ValidateEnvPlaceholdersPassTest extends TestCase { $container = new ContainerBuilder(); $container->registerExtension($ext = new EnvExtension()); - $container->prependExtensionConfig('env_extension', $expected = array( + $container->prependExtensionConfig('env_extension', $expected = [ 'scalar_node_not_empty_validated' => '%env(SOME)%', - )); + ]); $this->doProcess($container); @@ -234,9 +234,9 @@ class ValidateEnvPlaceholdersPassTest extends TestCase { $container = new ContainerBuilder(); $container->registerExtension($ext = new EnvExtension()); - $container->prependExtensionConfig('env_extension', $expected = array( + $container->prependExtensionConfig('env_extension', $expected = [ 'scalar_node_not_empty_validated' => 'foo %env(SOME)% bar', - )); + ]); $this->doProcess($container); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index a296f8cde9..6f1fb76719 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -453,7 +453,7 @@ class PhpDumperTest extends TestCase $dumper = new PhpDumper($container); $dumper->dump(); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_default_env.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_DefaultParameters'))); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_default_env.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_DefaultParameters'])); require self::$fixturesPath.'/php/services_default_env.php'; $container = new \Symfony_DI_PhpDumper_Test_DefaultParameters(); diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php index fe2cf669b4..dac52ff562 100644 --- a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php @@ -52,7 +52,7 @@ class CrawlerTest extends TestCase $crawler->add($this->createNodeList()); $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->add() adds nodes from a \DOMNodeList'); - $list = array(); + $list = []; foreach ($this->createNodeList() as $node) { $list[] = $node; } @@ -269,7 +269,7 @@ EOF public function testAddNodes() { - $list = array(); + $list = []; foreach ($this->createNodeList() as $node) { $list[] = $node; } @@ -314,7 +314,7 @@ EOF return $i.'-'.$node->text(); }); - $this->assertEquals(array('0-One', '1-Two', '2-Three'), $data, '->each() executes an anonymous function on each node of the list'); + $this->assertEquals(['0-One', '1-Two', '2-Three'], $data, '->each() executes an anonymous function on each node of the list'); } public function testIteration() @@ -415,13 +415,13 @@ EOF { $crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li'); - $this->assertEquals(array('One', 'Two', 'Three'), $crawler->extract('_text'), '->extract() returns an array of extracted data from the node list'); - $this->assertEquals(array(array('One', 'first'), array('Two', ''), array('Three', '')), $crawler->extract(array('_text', 'class')), '->extract() returns an array of extracted data from the node list'); - $this->assertEquals(array(array(), array(), array()), $crawler->extract(array()), '->extract() returns empty arrays if the attribute list is empty'); + $this->assertEquals(['One', 'Two', 'Three'], $crawler->extract('_text'), '->extract() returns an array of extracted data from the node list'); + $this->assertEquals([['One', 'first'], ['Two', ''], ['Three', '']], $crawler->extract(['_text', 'class']), '->extract() returns an array of extracted data from the node list'); + $this->assertEquals([[], [], []], $crawler->extract([]), '->extract() returns empty arrays if the attribute list is empty'); - $this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->extract('_text'), '->extract() returns an empty array if the node list is empty'); + $this->assertEquals([], $this->createTestCrawler()->filterXPath('//ol')->extract('_text'), '->extract() returns an empty array if the node list is empty'); - $this->assertEquals(array(array('One', 'li'), array('Two', 'li'), array('Three', 'li')), $crawler->extract(array('_text', '_name')), '->extract() returns an array of extracted data from the node list'); + $this->assertEquals([['One', 'li'], ['Two', 'li'], ['Three', 'li']], $crawler->extract(['_text', '_name']), '->extract() returns an array of extracted data from the node list'); } public function testFilterXpathComplexQueries() @@ -855,7 +855,7 @@ HTML; $links = $crawler->links(); $this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Link', $links[0], '->links() returns an array of Link instances'); - $this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty'); + $this->assertEquals([], $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty'); } public function testImages() @@ -867,7 +867,7 @@ HTML; $images = $crawler->images(); $this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Image', $images[0], '->images() returns an array of Image instances'); - $this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty'); + $this->assertEquals([], $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty'); } public function testForm() @@ -880,9 +880,9 @@ HTML; $this->assertEquals($crawler->form()->getFormNode()->getAttribute('id'), $crawler2->form()->getFormNode()->getAttribute('id'), '->form() works on elements with form attribute'); - $this->assertEquals(array('FooName' => 'FooBar', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'), $crawler->form(array('FooName' => 'FooBar'))->getValues(), '->form() takes an array of values to submit as its first argument'); - $this->assertEquals(array('FooName' => 'FooValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'), $crawler->form()->getValues(), '->getValues() returns correct form values'); - $this->assertEquals(array('FooBarName' => 'FooBarValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'), $crawler2->form()->getValues(), '->getValues() returns correct form values'); + $this->assertEquals(['FooName' => 'FooBar', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'], $crawler->form(['FooName' => 'FooBar'])->getValues(), '->form() takes an array of values to submit as its first argument'); + $this->assertEquals(['FooName' => 'FooValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'], $crawler->form()->getValues(), '->getValues() returns correct form values'); + $this->assertEquals(['FooBarName' => 'FooBarValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'], $crawler2->form()->getValues(), '->getValues() returns correct form values'); try { $this->createTestCrawler()->filterXPath('//ol')->form(); @@ -1072,13 +1072,13 @@ HTML; public function getBaseTagData() { - return array( - array('http://base.com', 'link', 'http://base.com/link'), - array('//base.com', 'link', 'https://base.com/link', 'https://domain.com', ' tag can use a schema-less URL'), - array('path/', 'link', 'https://domain.com/path/link', 'https://domain.com', ' tag can set a path'), - array('http://base.com', '#', 'http://base.com#', 'http://domain.com/path/link', ' tag does work with links to an anchor'), - array('http://base.com', '', 'http://base.com', 'http://domain.com/path/link', ' tag does work with empty links'), - ); + return [ + ['http://base.com', 'link', 'http://base.com/link'], + ['//base.com', 'link', 'https://base.com/link', 'https://domain.com', ' tag can use a schema-less URL'], + ['path/', 'link', 'https://domain.com/path/link', 'https://domain.com', ' tag can set a path'], + ['http://base.com', '#', 'http://base.com#', 'http://domain.com/path/link', ' tag does work with links to an anchor'], + ['http://base.com', '', 'http://base.com', 'http://domain.com/path/link', ' tag does work with empty links'], + ]; } /** @@ -1092,14 +1092,14 @@ HTML; public function getBaseTagWithFormData() { - return array( - array('https://base.com/', 'link/', 'https://base.com/link/', 'https://base.com/link/', ' tag does work with a path and relative form action'), - array('/basepath', '/registration', 'http://domain.com/registration', 'http://domain.com/registration', ' tag does work with a path and form action'), - array('/basepath', '', 'http://domain.com/registration', 'http://domain.com/registration', ' tag does work with a path and empty form action'), - array('http://base.com/', '/registration', 'http://base.com/registration', 'http://domain.com/registration', ' tag does work with a URL and form action'), - array('http://base.com', '', 'http://domain.com/path/form', 'http://domain.com/path/form', ' tag does work with a URL and an empty form action'), - array('http://base.com/path', '/registration', 'http://base.com/registration', 'http://domain.com/path/form', ' tag does work with a URL and form action'), - ); + return [ + ['https://base.com/', 'link/', 'https://base.com/link/', 'https://base.com/link/', ' tag does work with a path and relative form action'], + ['/basepath', '/registration', 'http://domain.com/registration', 'http://domain.com/registration', ' tag does work with a path and form action'], + ['/basepath', '', 'http://domain.com/registration', 'http://domain.com/registration', ' tag does work with a path and empty form action'], + ['http://base.com/', '/registration', 'http://base.com/registration', 'http://domain.com/registration', ' tag does work with a URL and form action'], + ['http://base.com', '', 'http://domain.com/path/form', 'http://domain.com/path/form', ' tag does work with a URL and an empty form action'], + ['http://base.com/path', '/registration', 'http://base.com/registration', 'http://domain.com/path/form', ' tag does work with a URL and form action'], + ]; } public function testCountOfNestedElements() @@ -1115,7 +1115,7 @@ HTML; $result = $crawler->filterXPath('//form/input')->evaluate('substring-before(@name, "Name")'); - $this->assertSame(array('Text', 'Foo', 'Bar'), $result); + $this->assertSame(['Text', 'Foo', 'Bar'], $result); } public function testEvaluateReturnsTypedResultOfNamespacedXPathExpressionOnADocumentSubset() @@ -1124,7 +1124,7 @@ HTML; $result = $crawler->filterXPath('//yt:accessControl/@action')->evaluate('string(.)'); - $this->assertSame(array('comment', 'videoRespond'), $result); + $this->assertSame(['comment', 'videoRespond'], $result); } public function testEvaluateReturnsTypedResultOfNamespacedXPathExpression() @@ -1134,7 +1134,7 @@ HTML; $result = $crawler->evaluate('string(//youtube:accessControl/@action)'); - $this->assertSame(array('comment'), $result); + $this->assertSame(['comment'], $result); } public function testEvaluateReturnsACrawlerIfXPathExpressionEvaluatesToANode() diff --git a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php index a4e317d3ce..75c87c1b0b 100644 --- a/src/Symfony/Component/Dotenv/Tests/DotenvTest.php +++ b/src/Symfony/Component/Dotenv/Tests/DotenvTest.php @@ -34,24 +34,24 @@ class DotenvTest extends TestCase public function getEnvDataWithFormatErrors() { - $tests = array( - array('FOO=BAR BAZ', "A value containing spaces must be surrounded by quotes in \".env\" at line 1.\n...FOO=BAR BAZ...\n ^ line 1 offset 11"), - array('FOO BAR=BAR', "Whitespace are not supported after the variable name in \".env\" at line 1.\n...FOO BAR=BAR...\n ^ line 1 offset 3"), - array('FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"), - array('FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"), - array('FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"), - array('FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"), - array('export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"), - array('FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"), - array('FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"), - array('Стасян', "Invalid character in variable name in \".env\" at line 1.\n...Стасян...\n ^ line 1 offset 0"), - array('FOO!', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO!...\n ^ line 1 offset 3"), - array('FOO=$(echo foo', "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo...\n ^ line 1 offset 14"), - array('FOO=$(echo foo'."\n", "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo\\n...\n ^ line 1 offset 14"), - ); + $tests = [ + ['FOO=BAR BAZ', "A value containing spaces must be surrounded by quotes in \".env\" at line 1.\n...FOO=BAR BAZ...\n ^ line 1 offset 11"], + ['FOO BAR=BAR', "Whitespace are not supported after the variable name in \".env\" at line 1.\n...FOO BAR=BAR...\n ^ line 1 offset 3"], + ['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"], + ['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"], + ['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"], + ['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"], + ['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"], + ['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"], + ['FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"], + ['Стасян', "Invalid character in variable name in \".env\" at line 1.\n...Стасян...\n ^ line 1 offset 0"], + ['FOO!', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO!...\n ^ line 1 offset 3"], + ['FOO=$(echo foo', "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo...\n ^ line 1 offset 14"], + ['FOO=$(echo foo'."\n", "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo\\n...\n ^ line 1 offset 14"], + ]; if ('\\' !== \DIRECTORY_SEPARATOR) { - $tests[] = array('FOO=$((1dd2))', "Issue expanding a command (%s\n) in \".env\" at line 1.\n...FOO=$((1dd2))...\n ^ line 1 offset 13"); + $tests[] = ['FOO=$((1dd2))', "Issue expanding a command (%s\n) in \".env\" at line 1.\n...FOO=$((1dd2))...\n ^ line 1 offset 13"]; } return $tests; @@ -72,105 +72,105 @@ class DotenvTest extends TestCase $_ENV['REMOTE'] = 'remote'; $_SERVER['SERVERVAR'] = 'servervar'; - $tests = array( + $tests = [ // backslashes - array('FOO=foo\\\\bar', array('FOO' => 'foo\\bar')), - array("FOO='foo\\\\bar'", array('FOO' => 'foo\\\\bar')), - array('FOO="foo\\\\bar"', array('FOO' => 'foo\\bar')), + ['FOO=foo\\\\bar', ['FOO' => 'foo\\bar']], + ["FOO='foo\\\\bar'", ['FOO' => 'foo\\\\bar']], + ['FOO="foo\\\\bar"', ['FOO' => 'foo\\bar']], // escaped backslash in front of variable - array("BAR=bar\nFOO=foo\\\\\$BAR", array('BAR' => 'bar', 'FOO' => 'foo\\bar')), - array("BAR=bar\nFOO='foo\\\\\$BAR'", array('BAR' => 'bar', 'FOO' => 'foo\\\\$BAR')), - array("BAR=bar\nFOO=\"foo\\\\\$BAR\"", array('BAR' => 'bar', 'FOO' => 'foo\\bar')), + ["BAR=bar\nFOO=foo\\\\\$BAR", ['BAR' => 'bar', 'FOO' => 'foo\\bar']], + ["BAR=bar\nFOO='foo\\\\\$BAR'", ['BAR' => 'bar', 'FOO' => 'foo\\\\$BAR']], + ["BAR=bar\nFOO=\"foo\\\\\$BAR\"", ['BAR' => 'bar', 'FOO' => 'foo\\bar']], - array('FOO=foo\\\\\\$BAR', array('FOO' => 'foo\\$BAR')), - array('FOO=\'foo\\\\\\$BAR\'', array('FOO' => 'foo\\\\\\$BAR')), - array('FOO="foo\\\\\\$BAR"', array('FOO' => 'foo\\$BAR')), + ['FOO=foo\\\\\\$BAR', ['FOO' => 'foo\\$BAR']], + ['FOO=\'foo\\\\\\$BAR\'', ['FOO' => 'foo\\\\\\$BAR']], + ['FOO="foo\\\\\\$BAR"', ['FOO' => 'foo\\$BAR']], // spaces - array('FOO=bar', array('FOO' => 'bar')), - array(' FOO=bar ', array('FOO' => 'bar')), - array('FOO=', array('FOO' => '')), - array("FOO=\n\n\nBAR=bar", array('FOO' => '', 'BAR' => 'bar')), - array('FOO= ', array('FOO' => '')), - array("FOO=\nBAR=bar", array('FOO' => '', 'BAR' => 'bar')), + ['FOO=bar', ['FOO' => 'bar']], + [' FOO=bar ', ['FOO' => 'bar']], + ['FOO=', ['FOO' => '']], + ["FOO=\n\n\nBAR=bar", ['FOO' => '', 'BAR' => 'bar']], + ['FOO= ', ['FOO' => '']], + ["FOO=\nBAR=bar", ['FOO' => '', 'BAR' => 'bar']], // newlines - array("\n\nFOO=bar\r\n\n", array('FOO' => 'bar')), - array("FOO=bar\r\nBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')), - array("FOO=bar\rBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')), - array("FOO=bar\nBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')), + ["\n\nFOO=bar\r\n\n", ['FOO' => 'bar']], + ["FOO=bar\r\nBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']], + ["FOO=bar\rBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']], + ["FOO=bar\nBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']], // quotes - array("FOO=\"bar\"\n", array('FOO' => 'bar')), - array("FOO=\"bar'foo\"\n", array('FOO' => 'bar\'foo')), - array("FOO='bar'\n", array('FOO' => 'bar')), - array("FOO='bar\"foo'\n", array('FOO' => 'bar"foo')), - array("FOO=\"bar\\\"foo\"\n", array('FOO' => 'bar"foo')), - array('FOO="bar\nfoo"', array('FOO' => "bar\nfoo")), - array('FOO="bar\rfoo"', array('FOO' => "bar\rfoo")), - array('FOO=\'bar\nfoo\'', array('FOO' => 'bar\nfoo')), - array('FOO=\'bar\rfoo\'', array('FOO' => 'bar\rfoo')), - array('FOO=" FOO "', array('FOO' => ' FOO ')), - array('FOO=" "', array('FOO' => ' ')), - array('PATH="c:\\\\"', array('PATH' => 'c:\\')), - array("FOO=\"bar\nfoo\"", array('FOO' => "bar\nfoo")), - array('FOO=BAR\\"', array('FOO' => 'BAR"')), - array("FOO=BAR\\'BAZ", array('FOO' => "BAR'BAZ")), - array('FOO=\\"BAR', array('FOO' => '"BAR')), + ["FOO=\"bar\"\n", ['FOO' => 'bar']], + ["FOO=\"bar'foo\"\n", ['FOO' => 'bar\'foo']], + ["FOO='bar'\n", ['FOO' => 'bar']], + ["FOO='bar\"foo'\n", ['FOO' => 'bar"foo']], + ["FOO=\"bar\\\"foo\"\n", ['FOO' => 'bar"foo']], + ['FOO="bar\nfoo"', ['FOO' => "bar\nfoo"]], + ['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]], + ['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']], + ['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']], + ['FOO=" FOO "', ['FOO' => ' FOO ']], + ['FOO=" "', ['FOO' => ' ']], + ['PATH="c:\\\\"', ['PATH' => 'c:\\']], + ["FOO=\"bar\nfoo\"", ['FOO' => "bar\nfoo"]], + ['FOO=BAR\\"', ['FOO' => 'BAR"']], + ["FOO=BAR\\'BAZ", ['FOO' => "BAR'BAZ"]], + ['FOO=\\"BAR', ['FOO' => '"BAR']], // concatenated values - array("FOO='bar''foo'\n", array('FOO' => 'barfoo')), - array("FOO='bar '' baz'", array('FOO' => 'bar baz')), - array("FOO=bar\nBAR='baz'\"\$FOO\"", array('FOO' => 'bar', 'BAR' => 'bazbar')), - array("FOO='bar '\\'' baz'", array('FOO' => "bar ' baz")), + ["FOO='bar''foo'\n", ['FOO' => 'barfoo']], + ["FOO='bar '' baz'", ['FOO' => 'bar baz']], + ["FOO=bar\nBAR='baz'\"\$FOO\"", ['FOO' => 'bar', 'BAR' => 'bazbar']], + ["FOO='bar '\\'' baz'", ['FOO' => "bar ' baz"]], // comments - array("#FOO=bar\nBAR=foo", array('BAR' => 'foo')), - array("#FOO=bar # Comment\nBAR=foo", array('BAR' => 'foo')), - array("FOO='bar foo' # Comment", array('FOO' => 'bar foo')), - array("FOO='bar#foo' # Comment", array('FOO' => 'bar#foo')), - array("# Comment\r\nFOO=bar\n# Comment\nBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')), - array("FOO=bar # Another comment\nBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')), - array("FOO=\n\n# comment\nBAR=bar", array('FOO' => '', 'BAR' => 'bar')), - array('FOO=NOT#COMMENT', array('FOO' => 'NOT#COMMENT')), - array('FOO= # Comment', array('FOO' => '')), + ["#FOO=bar\nBAR=foo", ['BAR' => 'foo']], + ["#FOO=bar # Comment\nBAR=foo", ['BAR' => 'foo']], + ["FOO='bar foo' # Comment", ['FOO' => 'bar foo']], + ["FOO='bar#foo' # Comment", ['FOO' => 'bar#foo']], + ["# Comment\r\nFOO=bar\n# Comment\nBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']], + ["FOO=bar # Another comment\nBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']], + ["FOO=\n\n# comment\nBAR=bar", ['FOO' => '', 'BAR' => 'bar']], + ['FOO=NOT#COMMENT', ['FOO' => 'NOT#COMMENT']], + ['FOO= # Comment', ['FOO' => '']], // edge cases (no conversions, only strings as values) - array('FOO=0', array('FOO' => '0')), - array('FOO=false', array('FOO' => 'false')), - array('FOO=null', array('FOO' => 'null')), + ['FOO=0', ['FOO' => '0']], + ['FOO=false', ['FOO' => 'false']], + ['FOO=null', ['FOO' => 'null']], // export - array('export FOO=bar', array('FOO' => 'bar')), - array(' export FOO=bar', array('FOO' => 'bar')), + ['export FOO=bar', ['FOO' => 'bar']], + [' export FOO=bar', ['FOO' => 'bar']], // variable expansion - array("FOO=BAR\nBAR=\$FOO", array('FOO' => 'BAR', 'BAR' => 'BAR')), - array("FOO=BAR\nBAR=\"\$FOO\"", array('FOO' => 'BAR', 'BAR' => 'BAR')), - array("FOO=BAR\nBAR='\$FOO'", array('FOO' => 'BAR', 'BAR' => '$FOO')), - array("FOO_BAR9=BAR\nBAR=\$FOO_BAR9", array('FOO_BAR9' => 'BAR', 'BAR' => 'BAR')), - array("FOO=BAR\nBAR=\${FOO}Z", array('FOO' => 'BAR', 'BAR' => 'BARZ')), - array("FOO=BAR\nBAR=\$FOO}", array('FOO' => 'BAR', 'BAR' => 'BAR}')), - array("FOO=BAR\nBAR=\\\$FOO", array('FOO' => 'BAR', 'BAR' => '$FOO')), - array('FOO=" \\$ "', array('FOO' => ' $ ')), - array('FOO=" $ "', array('FOO' => ' $ ')), - array('BAR=$LOCAL', array('BAR' => 'local')), - array('BAR=$REMOTE', array('BAR' => 'remote')), - array('BAR=$SERVERVAR', array('BAR' => 'servervar')), - array('FOO=$NOTDEFINED', array('FOO' => '')), - ); + ["FOO=BAR\nBAR=\$FOO", ['FOO' => 'BAR', 'BAR' => 'BAR']], + ["FOO=BAR\nBAR=\"\$FOO\"", ['FOO' => 'BAR', 'BAR' => 'BAR']], + ["FOO=BAR\nBAR='\$FOO'", ['FOO' => 'BAR', 'BAR' => '$FOO']], + ["FOO_BAR9=BAR\nBAR=\$FOO_BAR9", ['FOO_BAR9' => 'BAR', 'BAR' => 'BAR']], + ["FOO=BAR\nBAR=\${FOO}Z", ['FOO' => 'BAR', 'BAR' => 'BARZ']], + ["FOO=BAR\nBAR=\$FOO}", ['FOO' => 'BAR', 'BAR' => 'BAR}']], + ["FOO=BAR\nBAR=\\\$FOO", ['FOO' => 'BAR', 'BAR' => '$FOO']], + ['FOO=" \\$ "', ['FOO' => ' $ ']], + ['FOO=" $ "', ['FOO' => ' $ ']], + ['BAR=$LOCAL', ['BAR' => 'local']], + ['BAR=$REMOTE', ['BAR' => 'remote']], + ['BAR=$SERVERVAR', ['BAR' => 'servervar']], + ['FOO=$NOTDEFINED', ['FOO' => '']], + ]; if ('\\' !== \DIRECTORY_SEPARATOR) { - $tests = array_merge($tests, array( + $tests = array_merge($tests, [ // command expansion - array('FOO=$(echo foo)', array('FOO' => 'foo')), - array('FOO=$((1+2))', array('FOO' => '3')), - array('FOO=FOO$((1+2))BAR', array('FOO' => 'FOO3BAR')), - array('FOO=$(echo "$(echo "$(echo "$(echo foo)")")")', array('FOO' => 'foo')), - array("FOO=$(echo \"Quotes won't be a problem\")", array('FOO' => 'Quotes won\'t be a problem')), - array("FOO=bar\nBAR=$(echo \"FOO is \$FOO\")", array('FOO' => 'bar', 'BAR' => 'FOO is bar')), - )); + ['FOO=$(echo foo)', ['FOO' => 'foo']], + ['FOO=$((1+2))', ['FOO' => '3']], + ['FOO=FOO$((1+2))BAR', ['FOO' => 'FOO3BAR']], + ['FOO=$(echo "$(echo "$(echo "$(echo foo)")")")', ['FOO' => 'foo']], + ["FOO=$(echo \"Quotes won't be a problem\")", ['FOO' => 'Quotes won\'t be a problem']], + ["FOO=bar\nBAR=$(echo \"FOO is \$FOO\")", ['FOO' => 'bar', 'BAR' => 'FOO is bar']], + ]); } return $tests; @@ -319,7 +319,7 @@ class DotenvTest extends TestCase $originalValue = $_SERVER['argc']; $dotenv = new Dotenv(); - $dotenv->populate(array('argc' => 'new_value')); + $dotenv->populate(['argc' => 'new_value']); $this->assertSame($originalValue, $_SERVER['argc']); } @@ -330,7 +330,7 @@ class DotenvTest extends TestCase $_SERVER['TEST_ENV_VAR'] = 'original_value'; $dotenv = new Dotenv(); - $dotenv->populate(array('TEST_ENV_VAR' => 'new_value')); + $dotenv->populate(['TEST_ENV_VAR' => 'new_value']); $this->assertSame('original_value', getenv('TEST_ENV_VAR')); } @@ -340,7 +340,7 @@ class DotenvTest extends TestCase $_SERVER['HTTP_TEST_ENV_VAR'] = 'http_value'; $dotenv = new Dotenv(); - $dotenv->populate(array('HTTP_TEST_ENV_VAR' => 'env_value')); + $dotenv->populate(['HTTP_TEST_ENV_VAR' => 'env_value']); $this->assertSame('env_value', getenv('HTTP_TEST_ENV_VAR')); $this->assertSame('env_value', $_ENV['HTTP_TEST_ENV_VAR']); @@ -352,7 +352,7 @@ class DotenvTest extends TestCase putenv('TEST_ENV_VAR_OVERRIDEN=original_value'); $dotenv = new Dotenv(); - $dotenv->populate(array('TEST_ENV_VAR_OVERRIDEN' => 'new_value'), true); + $dotenv->populate(['TEST_ENV_VAR_OVERRIDEN' => 'new_value'], true); $this->assertSame('new_value', getenv('TEST_ENV_VAR_OVERRIDEN')); $this->assertSame('new_value', $_ENV['TEST_ENV_VAR_OVERRIDEN']); @@ -374,7 +374,7 @@ class DotenvTest extends TestCase putenv('DATABASE_URL'); $dotenv = new Dotenv(); - $dotenv->populate(array('APP_DEBUG' => '1', 'DATABASE_URL' => 'mysql://root@localhost/db')); + $dotenv->populate(['APP_DEBUG' => '1', 'DATABASE_URL' => 'mysql://root@localhost/db']); $this->assertSame('APP_DEBUG,DATABASE_URL', getenv('SYMFONY_DOTENV_VARS')); @@ -391,8 +391,8 @@ class DotenvTest extends TestCase putenv('DATABASE_URL'); $dotenv = new Dotenv(); - $dotenv->populate(array('APP_DEBUG' => '0', 'DATABASE_URL' => 'mysql://root@localhost/db')); - $dotenv->populate(array('DATABASE_URL' => 'sqlite:///somedb.sqlite')); + $dotenv->populate(['APP_DEBUG' => '0', 'DATABASE_URL' => 'mysql://root@localhost/db']); + $dotenv->populate(['DATABASE_URL' => 'sqlite:///somedb.sqlite']); $this->assertSame('APP_ENV,DATABASE_URL', getenv('SYMFONY_DOTENV_VARS')); } @@ -407,7 +407,7 @@ class DotenvTest extends TestCase putenv('DOCUMENT_ROOT=/var/www'); $dotenv = new Dotenv(); - $dotenv->populate(array('FOO' => 'foo1', 'BAR' => 'bar1', 'BAZ' => 'baz1', 'DOCUMENT_ROOT' => '/boot')); + $dotenv->populate(['FOO' => 'foo1', 'BAR' => 'bar1', 'BAZ' => 'baz1', 'DOCUMENT_ROOT' => '/boot']); $this->assertSame('foo1', getenv('FOO')); $this->assertSame('bar1', getenv('BAR')); diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 50c5fd5fa4..6962c5facf 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -28,14 +28,14 @@ namespace Symfony\Component\EventDispatcher; */ class EventDispatcher implements EventDispatcherInterface { - private $listeners = array(); - private $sorted = array(); + private $listeners = []; + private $sorted = []; private $optimized; public function __construct() { if (__CLASS__ === \get_class($this)) { - $this->optimized = array(); + $this->optimized = []; } } @@ -49,7 +49,7 @@ class EventDispatcher implements EventDispatcherInterface } if (null !== $this->optimized && null !== $eventName) { - $listeners = $this->optimized[$eventName] ?? (empty($this->listeners[$eventName]) ? array() : $this->optimizeListeners($eventName)); + $listeners = $this->optimized[$eventName] ?? (empty($this->listeners[$eventName]) ? [] : $this->optimizeListeners($eventName)); } else { $listeners = $this->getListeners($eventName); } @@ -68,7 +68,7 @@ class EventDispatcher implements EventDispatcherInterface { if (null !== $eventName) { if (empty($this->listeners[$eventName])) { - return array(); + return []; } if (!isset($this->sorted[$eventName])) { @@ -175,12 +175,12 @@ class EventDispatcher implements EventDispatcherInterface { foreach ($subscriber->getSubscribedEvents() as $eventName => $params) { if (\is_string($params)) { - $this->addListener($eventName, array($subscriber, $params)); + $this->addListener($eventName, [$subscriber, $params]); } elseif (\is_string($params[0])) { - $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0); + $this->addListener($eventName, [$subscriber, $params[0]], isset($params[1]) ? $params[1] : 0); } else { foreach ($params as $listener) { - $this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0); + $this->addListener($eventName, [$subscriber, $listener[0]], isset($listener[1]) ? $listener[1] : 0); } } } @@ -194,10 +194,10 @@ class EventDispatcher implements EventDispatcherInterface foreach ($subscriber->getSubscribedEvents() as $eventName => $params) { if (\is_array($params) && \is_array($params[0])) { foreach ($params as $listener) { - $this->removeListener($eventName, array($subscriber, $listener[0])); + $this->removeListener($eventName, [$subscriber, $listener[0]]); } } else { - $this->removeListener($eventName, array($subscriber, \is_string($params) ? $params : $params[0])); + $this->removeListener($eventName, [$subscriber, \is_string($params) ? $params : $params[0]]); } } } @@ -228,7 +228,7 @@ class EventDispatcher implements EventDispatcherInterface private function sortListeners(string $eventName) { krsort($this->listeners[$eventName]); - $this->sorted[$eventName] = array(); + $this->sorted[$eventName] = []; foreach ($this->listeners[$eventName] as &$listeners) { foreach ($listeners as $k => $listener) { @@ -246,7 +246,7 @@ class EventDispatcher implements EventDispatcherInterface private function optimizeListeners(string $eventName): array { krsort($this->listeners[$eventName]); - $this->optimized[$eventName] = array(); + $this->optimized[$eventName] = []; foreach ($this->listeners[$eventName] as &$listeners) { foreach ($listeners as &$listener) { diff --git a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php index 4a533dfa56..98fd027a6a 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php @@ -50,15 +50,15 @@ class EventDispatcherTest extends TestCase public function testInitialState() { - $this->assertEquals(array(), $this->dispatcher->getListeners()); + $this->assertEquals([], $this->dispatcher->getListeners()); $this->assertFalse($this->dispatcher->hasListeners(self::preFoo)); $this->assertFalse($this->dispatcher->hasListeners(self::postFoo)); } public function testAddListener() { - $this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo')); - $this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo')); + $this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']); + $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']); $this->assertTrue($this->dispatcher->hasListeners()); $this->assertTrue($this->dispatcher->hasListeners(self::preFoo)); $this->assertTrue($this->dispatcher->hasListeners(self::postFoo)); @@ -76,15 +76,15 @@ class EventDispatcherTest extends TestCase $listener2->name = '2'; $listener3->name = '3'; - $this->dispatcher->addListener('pre.foo', array($listener1, 'preFoo'), -10); - $this->dispatcher->addListener('pre.foo', array($listener2, 'preFoo'), 10); - $this->dispatcher->addListener('pre.foo', array($listener3, 'preFoo')); + $this->dispatcher->addListener('pre.foo', [$listener1, 'preFoo'], -10); + $this->dispatcher->addListener('pre.foo', [$listener2, 'preFoo'], 10); + $this->dispatcher->addListener('pre.foo', [$listener3, 'preFoo']); - $expected = array( - array($listener2, 'preFoo'), - array($listener3, 'preFoo'), - array($listener1, 'preFoo'), - ); + $expected = [ + [$listener2, 'preFoo'], + [$listener3, 'preFoo'], + [$listener1, 'preFoo'], + ]; $this->assertSame($expected, $this->dispatcher->getListeners('pre.foo')); } @@ -105,10 +105,10 @@ class EventDispatcherTest extends TestCase $this->dispatcher->addListener('post.foo', $listener5); $this->dispatcher->addListener('post.foo', $listener6, 10); - $expected = array( - 'pre.foo' => array($listener3, $listener2, $listener1), - 'post.foo' => array($listener6, $listener5, $listener4), - ); + $expected = [ + 'pre.foo' => [$listener3, $listener2, $listener1], + 'post.foo' => [$listener6, $listener5, $listener4], + ]; $this->assertSame($expected, $this->dispatcher->getListeners()); } @@ -129,8 +129,8 @@ class EventDispatcherTest extends TestCase public function testDispatch() { - $this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo')); - $this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo')); + $this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']); + $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']); $this->dispatcher->dispatch(self::preFoo); $this->assertTrue($this->listener->preFooInvoked); $this->assertFalse($this->listener->postFooInvoked); @@ -160,8 +160,8 @@ class EventDispatcherTest extends TestCase // postFoo() stops the propagation, so only one listener should // be executed // Manually set priority to enforce $this->listener to be called first - $this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'), 10); - $this->dispatcher->addListener('post.foo', array($otherListener, 'postFoo')); + $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10); + $this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']); $this->dispatcher->dispatch(self::postFoo); $this->assertTrue($this->listener->postFooInvoked); $this->assertFalse($otherListener->postFooInvoked); @@ -169,7 +169,7 @@ class EventDispatcherTest extends TestCase public function testDispatchByPriority() { - $invoked = array(); + $invoked = []; $listener1 = function () use (&$invoked) { $invoked[] = '1'; }; @@ -183,7 +183,7 @@ class EventDispatcherTest extends TestCase $this->dispatcher->addListener('pre.foo', $listener2); $this->dispatcher->addListener('pre.foo', $listener3, 10); $this->dispatcher->dispatch(self::preFoo); - $this->assertEquals(array('3', '2', '1'), $invoked); + $this->assertEquals(['3', '2', '1'], $invoked); } public function testRemoveListener() @@ -261,7 +261,7 @@ class EventDispatcherTest extends TestCase public function testEventReceivesTheDispatcherInstanceAsArgument() { $listener = new TestWithDispatcher(); - $this->dispatcher->addListener('test', array($listener, 'foo')); + $this->dispatcher->addListener('test', [$listener, 'foo']); $this->assertNull($listener->name); $this->assertNull($listener->dispatcher); $this->dispatcher->dispatch('test'); @@ -298,7 +298,7 @@ class EventDispatcherTest extends TestCase $listener = function () {}; $this->dispatcher->addListener('foo', $listener); $this->dispatcher->removeListener('foo', $listener); - $this->assertSame(array(), $this->dispatcher->getListeners()); + $this->assertSame([], $this->dispatcher->getListeners()); } public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled() @@ -310,7 +310,7 @@ class EventDispatcherTest extends TestCase public function testHasListenersIsLazy() { $called = 0; - $listener = array(function () use (&$called) { ++$called; }, 'onFoo'); + $listener = [function () use (&$called) { ++$called; }, 'onFoo']; $this->dispatcher->addListener('foo', $listener); $this->assertTrue($this->dispatcher->hasListeners()); $this->assertTrue($this->dispatcher->hasListeners('foo')); @@ -325,7 +325,7 @@ class EventDispatcherTest extends TestCase return new TestWithDispatcher(); }; - $this->dispatcher->addListener('foo', array($factory, 'foo')); + $this->dispatcher->addListener('foo', [$factory, 'foo']); $this->assertSame(0, $called); $this->dispatcher->dispatch('foo', new Event()); $this->dispatcher->dispatch('foo', new Event()); @@ -337,14 +337,14 @@ class EventDispatcherTest extends TestCase $test = new TestWithDispatcher(); $factory = function () use ($test) { return $test; }; - $this->dispatcher->addListener('foo', array($factory, 'foo')); + $this->dispatcher->addListener('foo', [$factory, 'foo']); $this->assertTrue($this->dispatcher->hasListeners('foo')); - $this->dispatcher->removeListener('foo', array($test, 'foo')); + $this->dispatcher->removeListener('foo', [$test, 'foo']); $this->assertFalse($this->dispatcher->hasListeners('foo')); - $this->dispatcher->addListener('foo', array($test, 'foo')); + $this->dispatcher->addListener('foo', [$test, 'foo']); $this->assertTrue($this->dispatcher->hasListeners('foo')); - $this->dispatcher->removeListener('foo', array($factory, 'foo')); + $this->dispatcher->removeListener('foo', [$factory, 'foo']); $this->assertFalse($this->dispatcher->hasListeners('foo')); } @@ -353,12 +353,12 @@ class EventDispatcherTest extends TestCase $test = new TestWithDispatcher(); $factory = function () use ($test) { return $test; }; - $this->dispatcher->addListener('foo', array($factory, 'foo'), 3); - $this->assertSame(3, $this->dispatcher->getListenerPriority('foo', array($test, 'foo'))); - $this->dispatcher->removeListener('foo', array($factory, 'foo')); + $this->dispatcher->addListener('foo', [$factory, 'foo'], 3); + $this->assertSame(3, $this->dispatcher->getListenerPriority('foo', [$test, 'foo'])); + $this->dispatcher->removeListener('foo', [$factory, 'foo']); - $this->dispatcher->addListener('foo', array($test, 'foo'), 5); - $this->assertSame(5, $this->dispatcher->getListenerPriority('foo', array($factory, 'foo'))); + $this->dispatcher->addListener('foo', [$test, 'foo'], 5); + $this->assertSame(5, $this->dispatcher->getListenerPriority('foo', [$factory, 'foo'])); } public function testGetLazyListeners() @@ -366,31 +366,31 @@ class EventDispatcherTest extends TestCase $test = new TestWithDispatcher(); $factory = function () use ($test) { return $test; }; - $this->dispatcher->addListener('foo', array($factory, 'foo'), 3); - $this->assertSame(array(array($test, 'foo')), $this->dispatcher->getListeners('foo')); + $this->dispatcher->addListener('foo', [$factory, 'foo'], 3); + $this->assertSame([[$test, 'foo']], $this->dispatcher->getListeners('foo')); - $this->dispatcher->removeListener('foo', array($test, 'foo')); - $this->dispatcher->addListener('bar', array($factory, 'foo'), 3); - $this->assertSame(array('bar' => array(array($test, 'foo'))), $this->dispatcher->getListeners()); + $this->dispatcher->removeListener('foo', [$test, 'foo']); + $this->dispatcher->addListener('bar', [$factory, 'foo'], 3); + $this->assertSame(['bar' => [[$test, 'foo']]], $this->dispatcher->getListeners()); } public function testMutatingWhilePropagationIsStopped() { $testLoaded = false; $test = new TestEventListener(); - $this->dispatcher->addListener('foo', array($test, 'postFoo')); - $this->dispatcher->addListener('foo', array(function () use ($test, &$testLoaded) { + $this->dispatcher->addListener('foo', [$test, 'postFoo']); + $this->dispatcher->addListener('foo', [function () use ($test, &$testLoaded) { $testLoaded = true; return $test; - }, 'preFoo')); + }, 'preFoo']); $this->dispatcher->dispatch('foo'); $this->assertTrue($test->postFooInvoked); $this->assertFalse($test->preFooInvoked); - $this->assertsame(0, $this->dispatcher->getListenerPriority('foo', array($test, 'preFoo'))); + $this->assertsame(0, $this->dispatcher->getListenerPriority('foo', [$test, 'preFoo'])); $test->preFoo(new Event()); $this->dispatcher->dispatch('foo'); @@ -444,7 +444,7 @@ class TestEventSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { - return array('pre.foo' => 'preFoo', 'post.foo' => 'postFoo'); + return ['pre.foo' => 'preFoo', 'post.foo' => 'postFoo']; } } @@ -452,10 +452,10 @@ class TestEventSubscriberWithPriorities implements EventSubscriberInterface { public static function getSubscribedEvents() { - return array( - 'pre.foo' => array('preFoo', 10), - 'post.foo' => array('postFoo'), - ); + return [ + 'pre.foo' => ['preFoo', 10], + 'post.foo' => ['postFoo'], + ]; } } @@ -463,9 +463,9 @@ class TestEventSubscriberWithMultipleListeners implements EventSubscriberInterfa { public static function getSubscribedEvents() { - return array('pre.foo' => array( - array('preFoo1'), - array('preFoo2', 10), - )); + return ['pre.foo' => [ + ['preFoo1'], + ['preFoo2', 10], + ]]; } } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php b/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php index 8badd0817b..cac3ae2311 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php @@ -123,7 +123,7 @@ abstract class BaseType extends AbstractType 'auto_initialize' => true, ]); - $resolver->setAllowedTypes('block_prefix', array('null', 'string')); + $resolver->setAllowedTypes('block_prefix', ['null', 'string']); $resolver->setAllowedTypes('attr', 'array'); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php index f05f321da7..b6fe373d7b 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php @@ -24,7 +24,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase { $transformer = new DateIntervalToArrayTransformer(); $input = new \DateInterval('P1Y2M3DT4H5M6S'); - $output = array( + $output = [ 'years' => '1', 'months' => '2', 'days' => '3', @@ -32,14 +32,14 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase 'minutes' => '5', 'seconds' => '6', 'invert' => false, - ); + ]; $this->assertSame($output, $transformer->transform($input)); } public function testTransformEmpty() { $transformer = new DateIntervalToArrayTransformer(); - $output = array( + $output = [ 'years' => '', 'months' => '', 'days' => '', @@ -47,43 +47,43 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase 'minutes' => '', 'seconds' => '', 'invert' => false, - ); + ]; $this->assertSame($output, $transformer->transform(null)); } public function testTransformEmptyWithFields() { - $transformer = new DateIntervalToArrayTransformer(array('years', 'weeks', 'minutes', 'seconds')); - $output = array( + $transformer = new DateIntervalToArrayTransformer(['years', 'weeks', 'minutes', 'seconds']); + $output = [ 'years' => '', 'weeks' => '', 'minutes' => '', 'seconds' => '', - ); + ]; $this->assertSame($output, $transformer->transform(null)); } public function testTransformWithFields() { - $transformer = new DateIntervalToArrayTransformer(array('years', 'minutes', 'seconds')); + $transformer = new DateIntervalToArrayTransformer(['years', 'minutes', 'seconds']); $input = new \DateInterval('P1Y2M3DT4H5M6S'); - $output = array( + $output = [ 'years' => '1', 'minutes' => '5', 'seconds' => '6', - ); + ]; $this->assertSame($output, $transformer->transform($input)); } public function testTransformWithWeek() { - $transformer = new DateIntervalToArrayTransformer(array('weeks', 'minutes', 'seconds')); + $transformer = new DateIntervalToArrayTransformer(['weeks', 'minutes', 'seconds']); $input = new \DateInterval('P1Y2M3WT4H5M6S'); - $output = array( + $output = [ 'weeks' => '3', 'minutes' => '5', 'seconds' => '6', - ); + ]; $input = $transformer->transform($input); ksort($input); ksort($output); @@ -92,13 +92,13 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase public function testTransformWithZeroWeek() { - $transformer = new DateIntervalToArrayTransformer(array('weeks', 'minutes', 'seconds')); + $transformer = new DateIntervalToArrayTransformer(['weeks', 'minutes', 'seconds']); $input = new \DateInterval('P1Y2M0WT4H5M6S'); - $output = array( + $output = [ 'weeks' => '0', 'minutes' => '5', 'seconds' => '6', - ); + ]; $input = $transformer->transform($input); ksort($input); ksort($output); @@ -107,13 +107,13 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase public function testTransformDaysToWeeks() { - $transformer = new DateIntervalToArrayTransformer(array('weeks', 'minutes', 'seconds')); + $transformer = new DateIntervalToArrayTransformer(['weeks', 'minutes', 'seconds']); $input = new \DateInterval('P1Y2M23DT4H5M6S'); - $output = array( + $output = [ 'weeks' => '3', 'minutes' => '5', 'seconds' => '6', - ); + ]; $input = $transformer->transform($input); ksort($input); ksort($output); @@ -122,25 +122,25 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase public function testTransformDaysNotOverflowingToWeeks() { - $transformer = new DateIntervalToArrayTransformer(array('days', 'minutes', 'seconds')); + $transformer = new DateIntervalToArrayTransformer(['days', 'minutes', 'seconds']); $input = new \DateInterval('P1Y2M23DT4H5M6S'); - $output = array( + $output = [ 'days' => '23', 'minutes' => '5', 'seconds' => '6', - ); + ]; $this->assertSame($output, $transformer->transform($input)); } public function testTransformWithInvert() { - $transformer = new DateIntervalToArrayTransformer(array('years', 'invert')); + $transformer = new DateIntervalToArrayTransformer(['years', 'invert']); $input = new \DateInterval('P1Y'); $input->invert = 1; - $output = array( + $output = [ 'years' => '1', 'invert' => true, - ); + ]; $this->assertSame($output, $transformer->transform($input)); } @@ -148,7 +148,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase { $transformer = new DateIntervalToArrayTransformer(null, true); $input = new \DateInterval('P1Y2M3DT4H5M6S'); - $output = array( + $output = [ 'years' => '01', 'months' => '02', 'days' => '03', @@ -156,19 +156,19 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase 'minutes' => '05', 'seconds' => '06', 'invert' => false, - ); + ]; $this->assertSame($output, $transformer->transform($input)); } public function testTransformWithFieldsAndPadding() { - $transformer = new DateIntervalToArrayTransformer(array('years', 'minutes', 'seconds'), true); + $transformer = new DateIntervalToArrayTransformer(['years', 'minutes', 'seconds'], true); $input = new \DateInterval('P1Y2M3DT4H5M6S'); - $output = array( + $output = [ 'years' => '01', 'minutes' => '05', 'seconds' => '06', - ); + ]; $this->assertSame($output, $transformer->transform($input)); } @@ -183,19 +183,19 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase public function testReverseTransformWithUnsetFields() { $transformer = new DateIntervalToArrayTransformer(); - $input = array('years' => '1'); + $input = ['years' => '1']; $this->expectException(TransformationFailedException::class); $transformer->reverseTransform($input); } public function testReverseTransformWithEmptyFields() { - $transformer = new DateIntervalToArrayTransformer(array('years', 'minutes', 'seconds')); - $input = array( + $transformer = new DateIntervalToArrayTransformer(['years', 'minutes', 'seconds']); + $input = [ 'years' => '1', 'minutes' => '', 'seconds' => '6', - ); + ]; if (method_exists($this, 'expectException')) { $this->expectException(TransformationFailedException::class); $this->expectExceptionMessage('This amount of "minutes" is invalid'); @@ -207,10 +207,10 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase public function testReverseTransformWithWrongInvertType() { - $transformer = new DateIntervalToArrayTransformer(array('invert')); - $input = array( + $transformer = new DateIntervalToArrayTransformer(['invert']); + $input = [ 'invert' => '1', - ); + ]; if (method_exists($this, 'expectException')) { $this->expectException(TransformationFailedException::class); $this->expectExceptionMessage('The value of "invert" must be boolean'); @@ -223,7 +223,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase public function testReverseTransform() { $transformer = new DateIntervalToArrayTransformer(); - $input = array( + $input = [ 'years' => '1', 'months' => '2', 'days' => '3', @@ -231,7 +231,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase 'minutes' => '5', 'seconds' => '6', 'invert' => false, - ); + ]; $output = new \DateInterval('P01Y02M03DT04H05M06S'); $this->assertDateIntervalEquals($output, $transformer->reverseTransform($input)); } @@ -239,28 +239,28 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase public function testReverseTransformWithWeek() { $transformer = new DateIntervalToArrayTransformer( - array('years', 'months', 'weeks', 'hours', 'minutes', 'seconds') + ['years', 'months', 'weeks', 'hours', 'minutes', 'seconds'] ); - $input = array( + $input = [ 'years' => '1', 'months' => '2', 'weeks' => '3', 'hours' => '4', 'minutes' => '5', 'seconds' => '6', - ); + ]; $output = new \DateInterval('P1Y2M21DT4H5M6S'); $this->assertDateIntervalEquals($output, $transformer->reverseTransform($input)); } public function testReverseTransformWithFields() { - $transformer = new DateIntervalToArrayTransformer(array('years', 'minutes', 'seconds')); - $input = array( + $transformer = new DateIntervalToArrayTransformer(['years', 'minutes', 'seconds']); + $input = [ 'years' => '1', 'minutes' => '5', 'seconds' => '6', - ); + ]; $output = new \DateInterval('P1Y0M0DT0H5M6S'); $this->assertDateIntervalEquals($output, $transformer->reverseTransform($input)); } @@ -268,17 +268,17 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase public function testBothTransformsWithWeek() { $transformer = new DateIntervalToArrayTransformer( - array('years', 'months', 'weeks', 'hours', 'minutes', 'seconds') + ['years', 'months', 'weeks', 'hours', 'minutes', 'seconds'] ); $interval = new \DateInterval('P1Y2M21DT4H5M6S'); - $array = array( + $array = [ 'years' => '1', 'months' => '2', 'weeks' => '3', 'hours' => '4', 'minutes' => '5', 'seconds' => '6', - ); + ]; $input = $transformer->transform($interval); ksort($input); ksort($array); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index 56ae48ce70..583a7c4f8b 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -20,22 +20,22 @@ class CollectionTypeTest extends BaseTypeTest public function testContainsNoChildByDefault() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, - )); + ]); $this->assertCount(0, $form); } public function testSetDataAdjustsSize() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, - 'entry_options' => array( - 'attr' => array('maxlength' => 20), - ), - )); - $form->setData(array('foo@foo.com', 'foo@bar.com')); + 'entry_options' => [ + 'attr' => ['maxlength' => 20], + ], + ]); + $form->setData(['foo@foo.com', 'foo@bar.com']); $this->assertInstanceOf('Symfony\Component\Form\Form', $form[0]); $this->assertInstanceOf('Symfony\Component\Form\Form', $form[1]); @@ -47,7 +47,7 @@ class CollectionTypeTest extends BaseTypeTest $this->assertEquals(20, $formAttrs0['maxlength']); $this->assertEquals(20, $formAttrs1['maxlength']); - $form->setData(array('foo@baz.com')); + $form->setData(['foo@baz.com']); $this->assertInstanceOf('Symfony\Component\Form\Form', $form[0]); $this->assertArrayNotHasKey(1, $form); $this->assertCount(1, $form); @@ -58,20 +58,20 @@ class CollectionTypeTest extends BaseTypeTest public function testThrowsExceptionIfObjectIsNotTraversable() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, - )); + ]); $this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException'); $form->setData(new \stdClass()); } public function testNotResizedIfSubmittedWithMissingData() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, - )); - $form->setData(array('foo@foo.com', 'bar@bar.com')); - $form->submit(array('foo@bar.com')); + ]); + $form->setData(['foo@foo.com', 'bar@bar.com']); + $form->submit(['foo@bar.com']); $this->assertTrue($form->has('0')); $this->assertTrue($form->has('1')); @@ -81,106 +81,106 @@ class CollectionTypeTest extends BaseTypeTest public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, 'allow_delete' => true, - )); - $form->setData(array('foo@foo.com', 'bar@bar.com')); - $form->submit(array('foo@foo.com')); + ]); + $form->setData(['foo@foo.com', 'bar@bar.com']); + $form->submit(['foo@foo.com']); $this->assertTrue($form->has('0')); $this->assertFalse($form->has('1')); $this->assertEquals('foo@foo.com', $form[0]->getData()); - $this->assertEquals(array('foo@foo.com'), $form->getData()); + $this->assertEquals(['foo@foo.com'], $form->getData()); } public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, 'allow_delete' => true, 'delete_empty' => true, - )); + ]); - $form->setData(array('foo@foo.com', 'bar@bar.com')); - $form->submit(array('foo@foo.com', '')); + $form->setData(['foo@foo.com', 'bar@bar.com']); + $form->submit(['foo@foo.com', '']); $this->assertTrue($form->has('0')); $this->assertFalse($form->has('1')); $this->assertEquals('foo@foo.com', $form[0]->getData()); - $this->assertEquals(array('foo@foo.com'), $form->getData()); + $this->assertEquals(['foo@foo.com'], $form->getData()); } public function testResizedDownWithDeleteEmptyCallable() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => AuthorType::class, 'allow_delete' => true, 'delete_empty' => function (Author $obj = null) { return null === $obj || empty($obj->firstName); }, - )); + ]); - $form->setData(array(new Author('Bob'), new Author('Alice'))); - $form->submit(array(array('firstName' => 'Bob'), array('firstName' => ''))); + $form->setData([new Author('Bob'), new Author('Alice')]); + $form->submit([['firstName' => 'Bob'], ['firstName' => '']]); $this->assertTrue($form->has('0')); $this->assertFalse($form->has('1')); $this->assertEquals(new Author('Bob'), $form[0]->getData()); - $this->assertEquals(array(new Author('Bob')), $form->getData()); + $this->assertEquals([new Author('Bob')], $form->getData()); } public function testResizedDownIfSubmittedWithCompoundEmptyDataDeleteEmptyAndNoDataClass() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => AuthorType::class, // If the field is not required, no new Author will be created if the // form is completely empty - 'entry_options' => array('data_class' => null), + 'entry_options' => ['data_class' => null], 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => function ($author) { return empty($author['firstName']); }, - )); - $form->setData(array(array('firstName' => 'first', 'lastName' => 'last'))); - $form->submit(array( - array('firstName' => 's_first', 'lastName' => 's_last'), - array('firstName' => '', 'lastName' => ''), - )); + ]); + $form->setData([['firstName' => 'first', 'lastName' => 'last']]); + $form->submit([ + ['firstName' => 's_first', 'lastName' => 's_last'], + ['firstName' => '', 'lastName' => ''], + ]); $this->assertTrue($form->has('0')); $this->assertFalse($form->has('1')); - $this->assertEquals(array('firstName' => 's_first', 'lastName' => 's_last'), $form[0]->getData()); - $this->assertEquals(array(array('firstName' => 's_first', 'lastName' => 's_last')), $form->getData()); + $this->assertEquals(['firstName' => 's_first', 'lastName' => 's_last'], $form[0]->getData()); + $this->assertEquals([['firstName' => 's_first', 'lastName' => 's_last']], $form->getData()); } public function testDontAddEmptyDataIfDeleteEmpty() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, 'allow_add' => true, 'delete_empty' => true, - )); + ]); - $form->setData(array('foo@foo.com')); - $form->submit(array('foo@foo.com', '')); + $form->setData(['foo@foo.com']); + $form->submit(['foo@foo.com', '']); $this->assertTrue($form->has('0')); $this->assertFalse($form->has('1')); $this->assertEquals('foo@foo.com', $form[0]->getData()); - $this->assertEquals(array('foo@foo.com'), $form->getData()); + $this->assertEquals(['foo@foo.com'], $form->getData()); } public function testNoDeleteEmptyIfDeleteNotAllowed() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, 'allow_delete' => false, 'delete_empty' => true, - )); + ]); - $form->setData(array('foo@foo.com')); - $form->submit(array('')); + $form->setData(['foo@foo.com']); + $form->submit(['']); $this->assertTrue($form->has('0')); $this->assertEquals('', $form[0]->getData()); @@ -188,34 +188,34 @@ class CollectionTypeTest extends BaseTypeTest public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => 'Symfony\Component\Form\Tests\Fixtures\AuthorType', // If the field is not required, no new Author will be created if the // form is completely empty - 'entry_options' => array('required' => false), + 'entry_options' => ['required' => false], 'allow_add' => true, 'delete_empty' => true, - )); + ]); - $form->setData(array(new Author('first', 'last'))); - $form->submit(array( - array('firstName' => 's_first', 'lastName' => 's_last'), - array('firstName' => '', 'lastName' => ''), - )); + $form->setData([new Author('first', 'last')]); + $form->submit([ + ['firstName' => 's_first', 'lastName' => 's_last'], + ['firstName' => '', 'lastName' => ''], + ]); $this->assertTrue($form->has('0')); $this->assertFalse($form->has('1')); $this->assertEquals(new Author('s_first', 's_last'), $form[0]->getData()); - $this->assertEquals(array(new Author('s_first', 's_last')), $form->getData()); + $this->assertEquals([new Author('s_first', 's_last')], $form->getData()); } public function testNotResizedIfSubmittedWithExtraData() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, - )); - $form->setData(array('foo@bar.com')); - $form->submit(array('foo@foo.com', 'bar@bar.com')); + ]); + $form->setData(['foo@bar.com']); + $form->submit(['foo@foo.com', 'bar@bar.com']); $this->assertTrue($form->has('0')); $this->assertFalse($form->has('1')); @@ -224,27 +224,27 @@ class CollectionTypeTest extends BaseTypeTest public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => TextTypeTest::TESTED_TYPE, 'allow_add' => true, - )); - $form->setData(array('foo@bar.com')); - $form->submit(array('foo@bar.com', 'bar@bar.com')); + ]); + $form->setData(['foo@bar.com']); + $form->submit(['foo@bar.com', 'bar@bar.com']); $this->assertTrue($form->has('0')); $this->assertTrue($form->has('1')); $this->assertEquals('foo@bar.com', $form[0]->getData()); $this->assertEquals('bar@bar.com', $form[1]->getData()); - $this->assertEquals(array('foo@bar.com', 'bar@bar.com'), $form->getData()); + $this->assertEquals(['foo@bar.com', 'bar@bar.com'], $form->getData()); } public function testAllowAddButNoPrototype() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => FormTypeTest::TESTED_TYPE, 'allow_add' => true, 'prototype' => false, - )); + ]); $this->assertFalse($form->has('__name__')); } @@ -252,11 +252,11 @@ class CollectionTypeTest extends BaseTypeTest public function testPrototypeMultipartPropagation() { $form = $this->factory - ->create(static::TESTED_TYPE, null, array( + ->create(static::TESTED_TYPE, null, [ 'entry_type' => FileTypeTest::TESTED_TYPE, 'allow_add' => true, 'prototype' => true, - )) + ]) ; $this->assertTrue($form->createView()->vars['multipart']); @@ -264,11 +264,11 @@ class CollectionTypeTest extends BaseTypeTest public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet() { - $form = $this->factory->create(static::TESTED_TYPE, array(), array( + $form = $this->factory->create(static::TESTED_TYPE, [], [ 'entry_type' => FileTypeTest::TESTED_TYPE, 'prototype' => true, 'allow_add' => true, - )); + ]); $data = $form->getData(); $this->assertArrayNotHasKey('__name__', $data); @@ -276,61 +276,61 @@ class CollectionTypeTest extends BaseTypeTest public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet() { - $form = $this->factory->create(static::TESTED_TYPE, array(), array( + $form = $this->factory->create(static::TESTED_TYPE, [], [ 'entry_type' => FileTypeTest::TESTED_TYPE, 'allow_add' => true, 'prototype' => true, - )); + ]); - $form->setData(array('foobar.png')); + $form->setData(['foobar.png']); $data = $form->getData(); $this->assertArrayNotHasKey('__name__', $data); } public function testPrototypeNameOption() { - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => FormTypeTest::TESTED_TYPE, 'prototype' => true, 'allow_add' => true, - )); + ]); $this->assertSame('__name__', $form->getConfig()->getAttribute('prototype')->getName(), '__name__ is the default'); - $form = $this->factory->create(static::TESTED_TYPE, null, array( + $form = $this->factory->create(static::TESTED_TYPE, null, [ 'entry_type' => FormTypeTest::TESTED_TYPE, 'prototype' => true, 'allow_add' => true, 'prototype_name' => '__test__', - )); + ]); $this->assertSame('__test__', $form->getConfig()->getAttribute('prototype')->getName()); } public function testPrototypeDefaultLabel() { - $form = $this->factory->create(static::TESTED_TYPE, array(), array( + $form = $this->factory->create(static::TESTED_TYPE, [], [ 'entry_type' => FileTypeTest::TESTED_TYPE, 'allow_add' => true, 'prototype' => true, 'prototype_name' => '__test__', - )); + ]); $this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']); } public function testPrototypeData() { - $form = $this->factory->create(static::TESTED_TYPE, array(), array( + $form = $this->factory->create(static::TESTED_TYPE, [], [ 'allow_add' => true, 'prototype' => true, 'prototype_data' => 'foo', 'entry_type' => TextTypeTest::TESTED_TYPE, - 'entry_options' => array( + 'entry_options' => [ 'data' => 'bar', 'label' => false, - ), - )); + ], + ]); $this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']); $this->assertFalse($form->createView()->vars['prototype']->vars['label']); @@ -338,25 +338,25 @@ class CollectionTypeTest extends BaseTypeTest public function testPrototypeDefaultRequired() { - $form = $this->factory->create(static::TESTED_TYPE, array(), array( + $form = $this->factory->create(static::TESTED_TYPE, [], [ 'entry_type' => FileTypeTest::TESTED_TYPE, 'allow_add' => true, 'prototype' => true, 'prototype_name' => '__test__', - )); + ]); $this->assertTrue($form->createView()->vars['prototype']->vars['required']); } public function testPrototypeSetNotRequired() { - $form = $this->factory->create(static::TESTED_TYPE, array(), array( + $form = $this->factory->create(static::TESTED_TYPE, [], [ 'entry_type' => FileTypeTest::TESTED_TYPE, 'allow_add' => true, 'prototype' => true, 'prototype_name' => '__test__', 'required' => false, - )); + ]); $this->assertFalse($form->createView()->vars['required'], 'collection is not required'); $this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required'); @@ -364,16 +364,16 @@ class CollectionTypeTest extends BaseTypeTest public function testPrototypeSetNotRequiredIfParentNotRequired() { - $child = $this->factory->create(static::TESTED_TYPE, array(), array( + $child = $this->factory->create(static::TESTED_TYPE, [], [ 'entry_type' => FileTypeTest::TESTED_TYPE, 'allow_add' => true, 'prototype' => true, 'prototype_name' => '__test__', - )); + ]); - $parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array( + $parent = $this->factory->create(FormTypeTest::TESTED_TYPE, [], [ 'required' => false, - )); + ]); $child->setParent($parent); $this->assertFalse($parent->createView()->vars['required'], 'Parent is not required'); @@ -383,19 +383,19 @@ class CollectionTypeTest extends BaseTypeTest public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent() { - $child = $this->factory->create(static::TESTED_TYPE, array(), array( + $child = $this->factory->create(static::TESTED_TYPE, [], [ 'entry_type' => FileTypeTest::TESTED_TYPE, 'allow_add' => true, 'prototype' => true, 'prototype_name' => '__test__', - 'entry_options' => array( + 'entry_options' => [ 'required' => true, - ), - )); + ], + ]); - $parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array( + $parent = $this->factory->create(FormTypeTest::TESTED_TYPE, [], [ 'required' => false, - )); + ]); $child->setParent($parent); @@ -406,10 +406,10 @@ class CollectionTypeTest extends BaseTypeTest public function testSubmitNull($expected = null, $norm = null, $view = null) { - parent::testSubmitNull(array(), array(), array()); + parent::testSubmitNull([], [], []); } - public function testSubmitNullUsesDefaultEmptyData($emptyData = array(), $expectedData = array()) + public function testSubmitNullUsesDefaultEmptyData($emptyData = [], $expectedData = []) { // resize form listener always set an empty array parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 5e0bb9e90f..47e7ae66be 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -643,12 +643,12 @@ class FormTypeTest extends BaseTypeTest public function testPassBlockPrefixToViewWithParent() { $view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE) - ->add('child', $this->getTestedType(), array( + ->add('child', $this->getTestedType(), [ 'block_prefix' => 'child', - )) + ]) ->getForm() ->createView(); - $this->assertSame(array('form', 'child', '_parent_child'), $view['child']->vars['block_prefixes']); + $this->assertSame(['form', 'child', '_parent_child'], $view['child']->vars['block_prefixes']); } } diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index 1df46ef28f..17c5f2624d 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -114,7 +114,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface } else { $dumper = new CliDumper('php://output', $this->charset); if (method_exists($dumper, 'setDisplayOptions')) { - $dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat)); + $dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]); } } @@ -219,7 +219,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface } else { $dumper = new CliDumper('php://output', $this->charset); if (method_exists($dumper, 'setDisplayOptions')) { - $dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat)); + $dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]); } } diff --git a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php index d862ad7306..9f5bb7a2af 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php @@ -55,7 +55,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte if ($this->logger instanceof DebugLoggerInterface) { $this->logger->clear(); } - $this->data = array(); + $this->data = []; } /** @@ -67,7 +67,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte $containerDeprecationLogs = $this->getContainerDeprecationLogs(); $this->data = $this->computeErrorsCount($containerDeprecationLogs); // get compiler logs later (only when they are needed) to improve performance - $this->data['compiler_logs'] = array(); + $this->data['compiler_logs'] = []; $this->data['compiler_logs_filepath'] = $this->containerPathPrefix.'Compiler.log'; $this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs($this->currentRequest), $containerDeprecationLogs)); $this->data = $this->cloneVar($this->data); @@ -82,12 +82,12 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte */ public function getLogs() { - return isset($this->data['logs']) ? $this->data['logs'] : array(); + return isset($this->data['logs']) ? $this->data['logs'] : []; } public function getPriorities() { - return isset($this->data['priorities']) ? $this->data['priorities'] : array(); + return isset($this->data['priorities']) ? $this->data['priorities'] : []; } public function countErrors() @@ -126,13 +126,13 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte private function getContainerDeprecationLogs() { if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) { - return array(); + return []; } $bootTime = filemtime($file); - $logs = array(); + $logs = []; foreach (unserialize(file_get_contents($file)) as $log) { - $log['context'] = array('exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])); + $log['context'] = ['exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])]; $log['timestamp'] = $bootTime; $log['priority'] = 100; $log['priorityName'] = 'DEBUG'; @@ -148,17 +148,17 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte private function getContainerCompilerLogs(?string $compilerLogsFilepath = null): array { if (!file_exists($compilerLogsFilepath)) { - return array(); + return []; } - $logs = array(); + $logs = []; foreach (file($compilerLogsFilepath, FILE_IGNORE_NEW_LINES) as $log) { $log = explode(': ', $log, 2); if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) { - $log = array('Unknown Compiler Pass', implode(': ', $log)); + $log = ['Unknown Compiler Pass', implode(': ', $log)]; } - $logs[$log[0]][] = array('message' => $log[1]); + $logs[$log[0]][] = ['message' => $log[1]]; } return $logs; @@ -166,8 +166,8 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte private function sanitizeLogs($logs) { - $sanitizedLogs = array(); - $silencedLogs = array(); + $sanitizedLogs = []; + $silencedLogs = []; foreach ($logs as $log) { if (!$this->isSilencedOrDeprecationErrorLog($log)) { @@ -186,10 +186,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte $silencedLogs[$h] = true; if (!isset($sanitizedLogs[$message])) { - $sanitizedLogs[$message] = $log + array( + $sanitizedLogs[$message] = $log + [ 'errorCount' => 0, 'scream' => true, - ); + ]; } $sanitizedLogs[$message]['errorCount'] += $exception->count; @@ -201,10 +201,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte if (isset($sanitizedLogs[$errorId])) { ++$sanitizedLogs[$errorId]['errorCount']; } else { - $log += array( + $log += [ 'errorCount' => 1, 'scream' => false, - ); + ]; $sanitizedLogs[$errorId] = $log; } @@ -225,7 +225,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte return true; } - if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), array(E_DEPRECATED, E_USER_DEPRECATED), true)) { + if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), [E_DEPRECATED, E_USER_DEPRECATED], true)) { return true; } @@ -234,23 +234,23 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte private function computeErrorsCount(array $containerDeprecationLogs) { - $silencedLogs = array(); - $count = array( + $silencedLogs = []; + $count = [ 'error_count' => $this->logger->countErrors($this->currentRequest), 'deprecation_count' => 0, 'warning_count' => 0, 'scream_count' => 0, - 'priorities' => array(), - ); + 'priorities' => [], + ]; foreach ($this->logger->getLogs($this->currentRequest) as $log) { if (isset($count['priorities'][$log['priority']])) { ++$count['priorities'][$log['priority']]['count']; } else { - $count['priorities'][$log['priority']] = array( + $count['priorities'][$log['priority']] = [ 'count' => 1, 'name' => $log['priorityName'], - ); + ]; } if ('WARNING' === $log['priorityName']) { ++$count['warning_count']; diff --git a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php index e14a1aaf2d..2372575517 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php @@ -45,6 +45,6 @@ class AddRequestFormatsListener implements EventSubscriberInterface */ public static function getSubscribedEvents() { - return array(KernelEvents::REQUEST => array('onKernelRequest', 100)); + return [KernelEvents::REQUEST => ['onKernelRequest', 100]]; } } diff --git a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php index 2c8e7744af..0c21d74020 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php @@ -79,13 +79,13 @@ class LocaleListener implements EventSubscriberInterface public static function getSubscribedEvents() { - return array( - KernelEvents::REQUEST => array( - array('setDefaultLocale', 100), + return [ + KernelEvents::REQUEST => [ + ['setDefaultLocale', 100], // must be registered after the Router to have access to the _locale - array('onKernelRequest', 16), - ), - KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)), - ); + ['onKernelRequest', 16], + ], + KernelEvents::FINISH_REQUEST => [['onKernelFinishRequest', 0]], + ]; } } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php index 4c5cdf0e70..b4f92f97c1 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -30,7 +30,7 @@ class AddRequestFormatsListenerTest extends TestCase protected function setUp() { - $this->listener = new AddRequestFormatsListener(array('csv' => array('text/csv', 'text/plain'))); + $this->listener = new AddRequestFormatsListener(['csv' => ['text/csv', 'text/plain']]); } protected function tearDown() @@ -46,7 +46,7 @@ class AddRequestFormatsListenerTest extends TestCase public function testRegisteredEvent() { $this->assertEquals( - array(KernelEvents::REQUEST => array('onKernelRequest', 100)), + [KernelEvents::REQUEST => ['onKernelRequest', 100]], AddRequestFormatsListener::getSubscribedEvents() ); } @@ -58,7 +58,7 @@ class AddRequestFormatsListenerTest extends TestCase $request->expects($this->once()) ->method('setFormat') - ->with('csv', array('text/csv', 'text/plain')); + ->with('csv', ['text/csv', 'text/plain']); $this->listener->onKernelRequest($event); } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php index 2ad903f4b1..5462fec978 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php @@ -36,10 +36,10 @@ class LocaleListenerTest extends TestCase public function testRegisteredEvent() { $this->assertEquals( - array( - KernelEvents::REQUEST => array(array('setDefaultLocale', 100), array('onKernelRequest', 16)), - KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)), - ), + [ + KernelEvents::REQUEST => [['setDefaultLocale', 100], ['onKernelRequest', 16]], + KernelEvents::FINISH_REQUEST => [['onKernelFinishRequest', 0]], + ], LocaleListener::getSubscribedEvents() ); } diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php index fbd49359dd..f5c856f9d5 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php @@ -38,7 +38,7 @@ class AdapterTest extends LdapTestCase $ldap = new Adapter($this->getLdapConfig()); $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); - $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array()); + $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', []); $result = $query->execute(); $this->assertInstanceOf(Collection::class, $result); @@ -46,8 +46,8 @@ class AdapterTest extends LdapTestCase $entry = $result[0]; $this->assertInstanceOf(Entry::class, $entry); - $this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn')); - $this->assertEquals(array('fabpot@symfony.com', 'fabien@potencier.com'), $entry->getAttribute('mail')); + $this->assertEquals(['Fabien Potencier'], $entry->getAttribute('cn')); + $this->assertEquals(['fabpot@symfony.com', 'fabien@potencier.com'], $entry->getAttribute('mail')); } /** @@ -58,14 +58,14 @@ class AdapterTest extends LdapTestCase $ldap = new Adapter($this->getLdapConfig()); $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); - $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array()); + $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', []); $result = $query->execute(); $iterator = $result->getIterator(); $iterator->rewind(); $entry = $iterator->current(); $this->assertInstanceOf(Entry::class, $entry); - $this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn')); - $this->assertEquals(array('fabpot@symfony.com', 'fabien@potencier.com'), $entry->getAttribute('mail')); + $this->assertEquals(['Fabien Potencier'], $entry->getAttribute('cn')); + $this->assertEquals(['fabpot@symfony.com', 'fabien@potencier.com'], $entry->getAttribute('mail')); } /** @@ -75,7 +75,7 @@ class AdapterTest extends LdapTestCase { $ldap = new Adapter($this->getLdapConfig()); $this->expectException(NotBoundException::class); - $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array()); + $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', []); $query->execute(); } @@ -85,14 +85,14 @@ class AdapterTest extends LdapTestCase $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); - $query = $ldap->createQuery('cn=Fabien Potencier,dc=symfony,dc=com', '(objectclass=*)', array( + $query = $ldap->createQuery('cn=Fabien Potencier,dc=symfony,dc=com', '(objectclass=*)', [ 'scope' => Query::SCOPE_BASE, - )); + ]); $result = $query->execute(); $entry = $result[0]; $this->assertEquals($result->count(), 1); - $this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn')); + $this->assertEquals(['Fabien Potencier'], $entry->getAttribute('cn')); } public function testLdapQueryScopeOneLevel() @@ -101,14 +101,14 @@ class AdapterTest extends LdapTestCase $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); - $one_level_result = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)', array( + $one_level_result = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)', [ 'scope' => Query::SCOPE_ONE, - ))->execute(); + ])->execute(); $subtree_count = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)')->execute()->count(); $this->assertNotEquals($one_level_result->count(), $subtree_count); $this->assertEquals($one_level_result->count(), 1); - $this->assertEquals($one_level_result[0]->getAttribute('ou'), array('Ldap')); + $this->assertEquals($one_level_result[0]->getAttribute('ou'), ['Ldap']); } } diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index fbb5cca0b0..92be7daa49 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -47,7 +47,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt * "?" and "#" (would be interpreted wrongly as query and fragment identifier), * "'" and """ (are used as delimiters in HTML). */ - protected $decodedChars = array( + protected $decodedChars = [ // the slash can be used to designate a hierarchical structure and we want allow using it with this meaning // some webservers don't allow the slash in encoded form in the path for security reasons anyway // see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss @@ -65,7 +65,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt '%21' => '!', '%2A' => '*', '%7C' => '|', - ); + ]; public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null, string $defaultLocale = null) { @@ -110,7 +110,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt /** * {@inheritdoc} */ - public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) + public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH) { $route = null; $locale = $parameters['_locale'] @@ -141,7 +141,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt * @throws InvalidParameterException When a parameter value for a placeholder is not correct because * it does not match the requirement */ - protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array()) + protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = []) { $variables = array_flip($variables); $mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters); @@ -165,11 +165,11 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt // check requirement if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#'.(empty($token[4]) ? '' : 'u'), $mergedParams[$varName])) { if ($this->strictRequirements) { - throw new InvalidParameterException(strtr($message, array('{parameter}' => $varName, '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$varName]))); + throw new InvalidParameterException(strtr($message, ['{parameter}' => $varName, '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$varName]])); } if ($this->logger) { - $this->logger->error($message, array('parameter' => $varName, 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$varName])); + $this->logger->error($message, ['parameter' => $varName, 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$varName]]); } return; @@ -195,7 +195,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt // the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3 // so we need to encode them as they are not used for this purpose here // otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route - $url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/')); + $url = strtr($url, ['/../' => '/%2E%2E/', '/./' => '/%2E/']); if ('/..' === substr($url, -3)) { $url = substr($url, 0, -2).'%2E%2E'; } elseif ('/.' === substr($url, -2)) { @@ -219,11 +219,11 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt if ('variable' === $token[0]) { if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) { if ($this->strictRequirements) { - throw new InvalidParameterException(strtr($message, array('{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]))); + throw new InvalidParameterException(strtr($message, ['{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]])); } if ($this->logger) { - $this->logger->error($message, array('parameter' => $token[3], 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$token[3]])); + $this->logger->error($message, ['parameter' => $token[3], 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$token[3]]]); } return; @@ -277,11 +277,11 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt if ($extra && $query = http_build_query($extra, '', '&', PHP_QUERY_RFC3986)) { // "/" and "?" can be left decoded for better user experience, see // http://tools.ietf.org/html/rfc3986#section-3.4 - $url .= '?'.strtr($query, array('%2F' => '/')); + $url .= '?'.strtr($query, ['%2F' => '/']); } if ('' !== $fragment) { - $url .= '#'.strtr(rawurlencode($fragment), array('%2F' => '/', '%3F' => '?')); + $url .= '#'.strtr(rawurlencode($fragment), ['%2F' => '/', '%3F' => '?']); } return $url; diff --git a/src/Symfony/Component/Routing/RouteCompiler.php b/src/Symfony/Component/Routing/RouteCompiler.php index abab86be7a..adf3cef8e1 100644 --- a/src/Symfony/Component/Routing/RouteCompiler.php +++ b/src/Symfony/Component/Routing/RouteCompiler.php @@ -46,10 +46,10 @@ class RouteCompiler implements RouteCompilerInterface */ public static function compile(Route $route) { - $hostVariables = array(); - $variables = array(); + $hostVariables = []; + $variables = []; $hostRegex = null; - $hostTokens = array(); + $hostTokens = []; if ('' !== $host = $route->getHost()) { $result = self::compilePattern($route, $host, true); @@ -94,9 +94,9 @@ class RouteCompiler implements RouteCompilerInterface private static function compilePattern(Route $route, $pattern, $isHost) { - $tokens = array(); - $variables = array(); - $matches = array(); + $tokens = []; + $variables = []; + $matches = []; $pos = 0; $defaultSeparator = $isHost ? '.' : '/'; $useUtf8 = preg_match('//u', $pattern); @@ -142,9 +142,9 @@ class RouteCompiler implements RouteCompilerInterface } if ($isSeparator && $precedingText !== $precedingChar) { - $tokens[] = array('text', substr($precedingText, 0, -\strlen($precedingChar))); + $tokens[] = ['text', substr($precedingText, 0, -\strlen($precedingChar))]; } elseif (!$isSeparator && \strlen($precedingText) > 0) { - $tokens[] = array('text', $precedingText); + $tokens[] = ['text', $precedingText]; } $regexp = $route->getRequirement($varName); @@ -183,7 +183,7 @@ class RouteCompiler implements RouteCompilerInterface $regexp = self::transformCapturingGroupsToNonCapturings($regexp); } - $tokens[] = array('variable', $isSeparator ? $precedingChar : '', $regexp, $varName); + $tokens[] = ['variable', $isSeparator ? $precedingChar : '', $regexp, $varName]; if ('!' === $varName[0]) { $varName = substr($varName, 1); } @@ -191,7 +191,7 @@ class RouteCompiler implements RouteCompilerInterface } if ($pos < \strlen($pattern)) { - $tokens[] = array('text', substr($pattern, $pos)); + $tokens[] = ['text', substr($pattern, $pos)]; } // find the first optional token @@ -224,12 +224,12 @@ class RouteCompiler implements RouteCompilerInterface } } - return array( + return [ 'staticPrefix' => self::determineStaticPrefix($route, $tokens), 'regex' => $regexp, 'tokens' => array_reverse($tokens), 'variables' => $variables, - ); + ]; } /** diff --git a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php index 44edbe7828..6a79609917 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php @@ -23,7 +23,7 @@ class UrlGeneratorTest extends TestCase public function testAbsoluteUrlWithPort80() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost/app.php/testing', $url); } @@ -31,7 +31,7 @@ class UrlGeneratorTest extends TestCase public function testAbsoluteSecureUrlWithPort443() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->getGenerator($routes, ['scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('https://localhost/app.php/testing', $url); } @@ -39,7 +39,7 @@ class UrlGeneratorTest extends TestCase public function testAbsoluteUrlWithNonStandardPort() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->getGenerator($routes, ['httpPort' => 8080])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost:8080/app.php/testing', $url); } @@ -47,7 +47,7 @@ class UrlGeneratorTest extends TestCase public function testAbsoluteSecureUrlWithNonStandardPort() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->getGenerator($routes, ['httpsPort' => 8080, 'scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('https://localhost:8080/app.php/testing', $url); } @@ -55,7 +55,7 @@ class UrlGeneratorTest extends TestCase public function testRelativeUrlWithoutParameters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH); + $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing', $url); } @@ -63,15 +63,15 @@ class UrlGeneratorTest extends TestCase public function testRelativeUrlWithParameter() { $routes = $this->getRoutes('test', new Route('/testing/{foo}')); - $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH); + $url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing/bar', $url); } public function testRelativeUrlWithNullParameter() { - $routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null))); - $url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH); + $routes = $this->getRoutes('test', new Route('/testing.{format}', ['format' => null])); + $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing', $url); } @@ -81,31 +81,31 @@ class UrlGeneratorTest extends TestCase */ public function testRelativeUrlWithNullParameterButNotOptional() { - $routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null))); + $routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', ['foo' => null])); // This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params. // Generating path "/testing//bar" would be wrong as matching this route would fail. - $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH); + $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH); } public function testRelativeUrlWithOptionalZeroParameter() { $routes = $this->getRoutes('test', new Route('/testing/{page}')); - $url = $this->getGenerator($routes)->generate('test', array('page' => 0), UrlGeneratorInterface::ABSOLUTE_PATH); + $url = $this->getGenerator($routes)->generate('test', ['page' => 0], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing/0', $url); } public function testNotPassedOptionalParameterInBetween() { - $routes = $this->getRoutes('test', new Route('/{slug}/{page}', array('slug' => 'index', 'page' => 0))); - $this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', array('page' => 1))); + $routes = $this->getRoutes('test', new Route('/{slug}/{page}', ['slug' => 'index', 'page' => 0])); + $this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', ['page' => 1])); $this->assertSame('/app.php/', $this->getGenerator($routes)->generate('test')); } public function testRelativeUrlWithExtraParameters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH); + $url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing?foo=bar', $url); } @@ -113,7 +113,7 @@ class UrlGeneratorTest extends TestCase public function testAbsoluteUrlWithExtraParameters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url); } @@ -121,7 +121,7 @@ class UrlGeneratorTest extends TestCase public function testUrlWithNullExtraParameters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array('foo' => null), UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->getGenerator($routes)->generate('test', ['foo' => null], UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost/app.php/testing', $url); } @@ -133,7 +133,7 @@ class UrlGeneratorTest extends TestCase $context = new RequestContext('/app.php'); $context->setParameter('bar', 'bar'); $generator->setContext($context); - $url = $generator->generate('test', array('foo' => 'bar')); + $url = $generator->generate('test', ['foo' => 'bar']); $this->assertEquals('/app.php/testing?foo=bar', $url); } @@ -145,19 +145,19 @@ class UrlGeneratorTest extends TestCase $context = new RequestContext('/app.php'); $context->setParameter('foo', 'bar'); $generator->setContext($context); - $url = $generator->generate('test', array()); + $url = $generator->generate('test', []); $this->assertEquals('/app.php/testing/bar', $url); } public function testGlobalParameterHasHigherPriorityThanDefault() { - $routes = $this->getRoutes('test', new Route('/{_locale}', array('_locale' => 'en'))); + $routes = $this->getRoutes('test', new Route('/{_locale}', ['_locale' => 'en'])); $generator = $this->getGenerator($routes); $context = new RequestContext('/app.php'); $context->setParameter('_locale', 'de'); $generator->setContext($context); - $url = $generator->generate('test', array()); + $url = $generator->generate('test', []); $this->assertSame('/app.php/de', $url); } @@ -168,7 +168,7 @@ class UrlGeneratorTest extends TestCase public function testGenerateWithoutRoutes() { $routes = $this->getRoutes('foo', new Route('/testing/{foo}')); - $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); + $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -177,7 +177,7 @@ class UrlGeneratorTest extends TestCase public function testGenerateForRouteWithoutMandatoryParameter() { $routes = $this->getRoutes('test', new Route('/testing/{foo}')); - $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); + $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -185,8 +185,8 @@ class UrlGeneratorTest extends TestCase */ public function testGenerateForRouteWithInvalidOptionalParameter() { - $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); - $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+'])); + $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -194,35 +194,35 @@ class UrlGeneratorTest extends TestCase */ public function testGenerateForRouteWithInvalidParameter() { - $routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '1|2'))); - $this->getGenerator($routes)->generate('test', array('foo' => '0'), UrlGeneratorInterface::ABSOLUTE_URL); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '1|2'])); + $this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL); } public function testGenerateForRouteWithInvalidOptionalParameterNonStrict() { - $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+'])); $generator = $this->getGenerator($routes); $generator->setStrictRequirements(false); - $this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL)); + $this->assertNull($generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL)); } public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger() { - $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+'])); $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $logger->expects($this->once()) ->method('error'); - $generator = $this->getGenerator($routes, array(), $logger); + $generator = $this->getGenerator($routes, [], $logger); $generator->setStrictRequirements(false); - $this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL)); + $this->assertNull($generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL)); } public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck() { - $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+'])); $generator = $this->getGenerator($routes); $generator->setStrictRequirements(null); - $this->assertSame('/app.php/testing/bar', $generator->generate('test', array('foo' => 'bar'))); + $this->assertSame('/app.php/testing/bar', $generator->generate('test', ['foo' => 'bar'])); } /** @@ -230,8 +230,8 @@ class UrlGeneratorTest extends TestCase */ public function testGenerateForRouteWithInvalidMandatoryParameter() { - $routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+'))); - $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => 'd+'])); + $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -239,8 +239,8 @@ class UrlGeneratorTest extends TestCase */ public function testGenerateForRouteWithInvalidUtf8Parameter() { - $routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '\pL+'), array('utf8' => true))); - $this->getGenerator($routes)->generate('test', array('foo' => 'abc123'), UrlGeneratorInterface::ABSOLUTE_URL); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '\pL+'], ['utf8' => true])); + $this->getGenerator($routes)->generate('test', ['foo' => 'abc123'], UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -248,31 +248,31 @@ class UrlGeneratorTest extends TestCase */ public function testRequiredParamAndEmptyPassed() { - $routes = $this->getRoutes('test', new Route('/{slug}', array(), array('slug' => '.+'))); - $this->getGenerator($routes)->generate('test', array('slug' => '')); + $routes = $this->getRoutes('test', new Route('/{slug}', [], ['slug' => '.+'])); + $this->getGenerator($routes)->generate('test', ['slug' => '']); } public function testSchemeRequirementDoesNothingIfSameCurrentScheme() { - $routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('http'))); + $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['http'])); $this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test')); - $routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('https'))); - $this->assertEquals('/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test')); + $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['https'])); + $this->assertEquals('/app.php/', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test')); } public function testSchemeRequirementForcesAbsoluteUrl() { - $routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('https'))); + $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['https'])); $this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test')); - $routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('http'))); - $this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test')); + $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['http'])); + $this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test')); } public function testSchemeRequirementCreatesUrlForFirstRequiredScheme() { - $routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('Ftp', 'https'))); + $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['Ftp', 'https'])); $this->assertEquals('ftp://localhost/app.php/', $this->getGenerator($routes)->generate('test')); } @@ -281,48 +281,48 @@ class UrlGeneratorTest extends TestCase $routes = $this->getRoutes('test', new Route('//path-and-not-domain')); // this must not generate '//path-and-not-domain' because that would be a network path - $this->assertSame('/path-and-not-domain', $this->getGenerator($routes, array('BaseUrl' => ''))->generate('test')); + $this->assertSame('/path-and-not-domain', $this->getGenerator($routes, ['BaseUrl' => ''])->generate('test')); } public function testNoTrailingSlashForMultipleOptionalParameters() { - $routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', array('slug2' => null, 'slug3' => null))); + $routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', ['slug2' => null, 'slug3' => null])); - $this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', array('slug1' => 'foo'))); + $this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', ['slug1' => 'foo'])); } public function testWithAnIntegerAsADefaultValue() { - $routes = $this->getRoutes('test', new Route('/{default}', array('default' => 0))); + $routes = $this->getRoutes('test', new Route('/{default}', ['default' => 0])); - $this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo'))); + $this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', ['default' => 'foo'])); } public function testNullForOptionalParameterIsIgnored() { - $routes = $this->getRoutes('test', new Route('/test/{default}', array('default' => 0))); + $routes = $this->getRoutes('test', new Route('/test/{default}', ['default' => 0])); - $this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => null))); + $this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', ['default' => null])); } public function testQueryParamSameAsDefault() { - $routes = $this->getRoutes('test', new Route('/test', array('page' => 1))); + $routes = $this->getRoutes('test', new Route('/test', ['page' => 1])); - $this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', array('page' => 2))); - $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => 1))); - $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => '1'))); + $this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', ['page' => 2])); + $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['page' => 1])); + $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['page' => '1'])); $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test')); } public function testArrayQueryParamSameAsDefault() { - $routes = $this->getRoutes('test', new Route('/test', array('array' => array('foo', 'bar')))); + $routes = $this->getRoutes('test', new Route('/test', ['array' => ['foo', 'bar']])); - $this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', array('array' => array('bar', 'foo')))); - $this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', array('array' => array('a' => 'foo', 'b' => 'bar')))); - $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array('foo', 'bar')))); - $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array(1 => 'bar', 0 => 'foo')))); + $this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', ['array' => ['bar', 'foo']])); + $this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', ['array' => ['a' => 'foo', 'b' => 'bar']])); + $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['array' => ['foo', 'bar']])); + $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['array' => [1 => 'bar', 0 => 'foo']])); $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test')); } @@ -342,11 +342,11 @@ class UrlGeneratorTest extends TestCase // This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986) // and other special ASCII chars. These chars are tested as static text path, variable path and query param. $chars = '@:[]/()*\'" +,;-._~&$<>|{}%\\^`!?foo=bar#id'; - $routes = $this->getRoutes('test', new Route("/$chars/{varpath}", array(), array('varpath' => '.+'))); - $this->assertSame($expectedPath, $this->getGenerator($routes)->generate('test', array( + $routes = $this->getRoutes('test', new Route("/$chars/{varpath}", [], ['varpath' => '.+'])); + $this->assertSame($expectedPath, $this->getGenerator($routes)->generate('test', [ 'varpath' => $chars, 'query' => $chars, - ))); + ])); } public function testEncodingOfRelativePathSegments() @@ -361,24 +361,24 @@ class UrlGeneratorTest extends TestCase public function testAdjacentVariables() { - $routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => '\d+'))); + $routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '\d+'])); $generator = $this->getGenerator($routes); - $this->assertSame('/app.php/foo123', $generator->generate('test', array('x' => 'foo', 'y' => '123'))); - $this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', array('x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml'))); + $this->assertSame('/app.php/foo123', $generator->generate('test', ['x' => 'foo', 'y' => '123'])); + $this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', ['x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml'])); // The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything // and following optional variables like _format could never match. $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException'); - $generator->generate('test', array('x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml')); + $generator->generate('test', ['x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml']); } public function testOptionalVariableWithNoRealSeparator() { - $routes = $this->getRoutes('test', new Route('/get{what}', array('what' => 'All'))); + $routes = $this->getRoutes('test', new Route('/get{what}', ['what' => 'All'])); $generator = $this->getGenerator($routes); $this->assertSame('/app.php/get', $generator->generate('test')); - $this->assertSame('/app.php/getSites', $generator->generate('test', array('what' => 'Sites'))); + $this->assertSame('/app.php/getSites', $generator->generate('test', ['what' => 'Sites'])); } public function testRequiredVariableWithNoRealSeparator() @@ -386,7 +386,7 @@ class UrlGeneratorTest extends TestCase $routes = $this->getRoutes('test', new Route('/get{what}Suffix')); $generator = $this->getGenerator($routes); - $this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', array('what' => 'Sites'))); + $this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', ['what' => 'Sites'])); } public function testDefaultRequirementOfVariable() @@ -394,17 +394,17 @@ class UrlGeneratorTest extends TestCase $routes = $this->getRoutes('test', new Route('/{page}.{_format}')); $generator = $this->getGenerator($routes); - $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index', '_format' => 'mobile.html'))); + $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index', '_format' => 'mobile.html'])); } public function testImportantVariable() { - $routes = $this->getRoutes('test', (new Route('/{page}.{!_format}'))->addDefaults(array('_format' => 'mobile.html'))); + $routes = $this->getRoutes('test', (new Route('/{page}.{!_format}'))->addDefaults(['_format' => 'mobile.html'])); $generator = $this->getGenerator($routes); - $this->assertSame('/app.php/index.xml', $generator->generate('test', array('page' => 'index', '_format' => 'xml'))); - $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index', '_format' => 'mobile.html'))); - $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index'))); + $this->assertSame('/app.php/index.xml', $generator->generate('test', ['page' => 'index', '_format' => 'xml'])); + $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index', '_format' => 'mobile.html'])); + $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index'])); } /** @@ -415,7 +415,7 @@ class UrlGeneratorTest extends TestCase $routes = $this->getRoutes('test', new Route('/{page}.{!_format}')); $generator = $this->getGenerator($routes); - $generator->generate('test', array('page' => 'index')); + $generator->generate('test', ['page' => 'index']); } /** @@ -424,7 +424,7 @@ class UrlGeneratorTest extends TestCase public function testDefaultRequirementOfVariableDisallowsSlash() { $routes = $this->getRoutes('test', new Route('/{page}.{_format}')); - $this->getGenerator($routes)->generate('test', array('page' => 'index', '_format' => 'sl/ash')); + $this->getGenerator($routes)->generate('test', ['page' => 'index', '_format' => 'sl/ash']); } /** @@ -433,28 +433,28 @@ class UrlGeneratorTest extends TestCase public function testDefaultRequirementOfVariableDisallowsNextSeparator() { $routes = $this->getRoutes('test', new Route('/{page}.{_format}')); - $this->getGenerator($routes)->generate('test', array('page' => 'do.t', '_format' => 'html')); + $this->getGenerator($routes)->generate('test', ['page' => 'do.t', '_format' => 'html']); } public function testWithHostDifferentFromContext() { - $routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com')); + $routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com')); - $this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', array('name' => 'Fabien', 'locale' => 'fr'))); + $this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', ['name' => 'Fabien', 'locale' => 'fr'])); } public function testWithHostSameAsContext() { - $routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com')); + $routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com')); - $this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'))); + $this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr'])); } public function testWithHostSameAsContextAndAbsolute() { - $routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com')); + $routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com')); - $this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL)); + $this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL)); } /** @@ -462,8 +462,8 @@ class UrlGeneratorTest extends TestCase */ public function testUrlWithInvalidParameterInHost() { - $routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com')); - $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH); + $routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com')); + $this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH); } /** @@ -471,8 +471,8 @@ class UrlGeneratorTest extends TestCase */ public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue() { - $routes = $this->getRoutes('test', new Route('/', array('foo' => 'bar'), array('foo' => 'bar'), array(), '{foo}.example.com')); - $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH); + $routes = $this->getRoutes('test', new Route('/', ['foo' => 'bar'], ['foo' => 'bar'], [], '{foo}.example.com')); + $this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH); } /** @@ -480,72 +480,72 @@ class UrlGeneratorTest extends TestCase */ public function testUrlWithInvalidParameterEqualsDefaultValueInHost() { - $routes = $this->getRoutes('test', new Route('/', array('foo' => 'baz'), array('foo' => 'bar'), array(), '{foo}.example.com')); - $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH); + $routes = $this->getRoutes('test', new Route('/', ['foo' => 'baz'], ['foo' => 'bar'], [], '{foo}.example.com')); + $this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH); } public function testUrlWithInvalidParameterInHostInNonStrictMode() { - $routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com')); + $routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com')); $generator = $this->getGenerator($routes); $generator->setStrictRequirements(false); - $this->assertNull($generator->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH)); + $this->assertNull($generator->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH)); } public function testHostIsCaseInsensitive() { - $routes = $this->getRoutes('test', new Route('/', array(), array('locale' => 'en|de|fr'), array(), '{locale}.FooBar.com')); + $routes = $this->getRoutes('test', new Route('/', [], ['locale' => 'en|de|fr'], [], '{locale}.FooBar.com')); $generator = $this->getGenerator($routes); - $this->assertSame('//EN.FooBar.com/app.php/', $generator->generate('test', array('locale' => 'EN'), UrlGeneratorInterface::NETWORK_PATH)); + $this->assertSame('//EN.FooBar.com/app.php/', $generator->generate('test', ['locale' => 'EN'], UrlGeneratorInterface::NETWORK_PATH)); } public function testDefaultHostIsUsedWhenContextHostIsEmpty() { - $routes = $this->getRoutes('test', new Route('/route', array('domain' => 'my.fallback.host'), array('domain' => '.+'), array(), '{domain}', array('http'))); + $routes = $this->getRoutes('test', new Route('/route', ['domain' => 'my.fallback.host'], ['domain' => '.+'], [], '{domain}', ['http'])); $generator = $this->getGenerator($routes); $generator->getContext()->setHost(''); - $this->assertSame('http://my.fallback.host/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL)); + $this->assertSame('http://my.fallback.host/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL)); } public function testDefaultHostIsUsedWhenContextHostIsEmptyAndSchemeIsNot() { - $routes = $this->getRoutes('test', new Route('/route', array('domain' => 'my.fallback.host'), array('domain' => '.+'), array(), '{domain}', array('http', 'https'))); + $routes = $this->getRoutes('test', new Route('/route', ['domain' => 'my.fallback.host'], ['domain' => '.+'], [], '{domain}', ['http', 'https'])); $generator = $this->getGenerator($routes); $generator->getContext()->setHost(''); $generator->getContext()->setScheme('https'); - $this->assertSame('https://my.fallback.host/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL)); + $this->assertSame('https://my.fallback.host/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL)); } public function testAbsoluteUrlFallbackToRelativeIfHostIsEmptyAndSchemeIsNot() { - $routes = $this->getRoutes('test', new Route('/route', array(), array(), array(), '', array('http', 'https'))); + $routes = $this->getRoutes('test', new Route('/route', [], [], [], '', ['http', 'https'])); $generator = $this->getGenerator($routes); $generator->getContext()->setHost(''); $generator->getContext()->setScheme('https'); - $this->assertSame('/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL)); + $this->assertSame('/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL)); } public function testGenerateNetworkPath() { - $routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com', array('http'))); + $routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com', ['http'])); $this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', - array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'network path with different host' + ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::NETWORK_PATH), 'network path with different host' ); - $this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', - array('name' => 'Fabien', 'locale' => 'fr', 'query' => 'string'), UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context' + $this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', + ['name' => 'Fabien', 'locale' => 'fr', 'query' => 'string'], UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context' ); - $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', - array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context' + $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test', + ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context' ); $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', - array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested' + ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested' ); } @@ -554,32 +554,32 @@ class UrlGeneratorTest extends TestCase $routes = new RouteCollection(); $routes->add('article', new Route('/{author}/{article}/')); $routes->add('comments', new Route('/{author}/{article}/comments')); - $routes->add('host', new Route('/{article}', array(), array(), array(), '{author}.example.com')); - $routes->add('scheme', new Route('/{author}/blog', array(), array(), array(), '', array('https'))); + $routes->add('host', new Route('/{article}', [], [], [], '{author}.example.com')); + $routes->add('scheme', new Route('/{author}/blog', [], [], [], '', ['https'])); $routes->add('unrelated', new Route('/about')); - $generator = $this->getGenerator($routes, array('host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/')); + $generator = $this->getGenerator($routes, ['host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/']); $this->assertSame('comments', $generator->generate('comments', - array('author' => 'fabien', 'article' => 'symfony-is-great'), UrlGeneratorInterface::RELATIVE_PATH) + ['author' => 'fabien', 'article' => 'symfony-is-great'], UrlGeneratorInterface::RELATIVE_PATH) ); $this->assertSame('comments?page=2', $generator->generate('comments', - array('author' => 'fabien', 'article' => 'symfony-is-great', 'page' => 2), UrlGeneratorInterface::RELATIVE_PATH) + ['author' => 'fabien', 'article' => 'symfony-is-great', 'page' => 2], UrlGeneratorInterface::RELATIVE_PATH) ); $this->assertSame('../twig-is-great/', $generator->generate('article', - array('author' => 'fabien', 'article' => 'twig-is-great'), UrlGeneratorInterface::RELATIVE_PATH) + ['author' => 'fabien', 'article' => 'twig-is-great'], UrlGeneratorInterface::RELATIVE_PATH) ); $this->assertSame('../../bernhard/forms-are-great/', $generator->generate('article', - array('author' => 'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH) + ['author' => 'bernhard', 'article' => 'forms-are-great'], UrlGeneratorInterface::RELATIVE_PATH) ); $this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('host', - array('author' => 'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH) + ['author' => 'bernhard', 'article' => 'forms-are-great'], UrlGeneratorInterface::RELATIVE_PATH) ); $this->assertSame('https://example.com/app.php/bernhard/blog', $generator->generate('scheme', - array('author' => 'bernhard'), UrlGeneratorInterface::RELATIVE_PATH) + ['author' => 'bernhard'], UrlGeneratorInterface::RELATIVE_PATH) ); $this->assertSame('../../about', $generator->generate('unrelated', - array(), UrlGeneratorInterface::RELATIVE_PATH) + [], UrlGeneratorInterface::RELATIVE_PATH) ); } @@ -593,138 +593,138 @@ class UrlGeneratorTest extends TestCase public function provideRelativePaths() { - return array( - array( + return [ + [ '/same/dir/', '/same/dir/', '', - ), - array( + ], + [ '/same/file', '/same/file', '', - ), - array( + ], + [ '/', '/file', 'file', - ), - array( + ], + [ '/', '/dir/file', 'dir/file', - ), - array( + ], + [ '/dir/file.html', '/dir/different-file.html', 'different-file.html', - ), - array( + ], + [ '/same/dir/extra-file', '/same/dir/', './', - ), - array( + ], + [ '/parent/dir/', '/parent/', '../', - ), - array( + ], + [ '/parent/dir/extra-file', '/parent/', '../', - ), - array( + ], + [ '/a/b/', '/x/y/z/', '../../x/y/z/', - ), - array( + ], + [ '/a/b/c/d/e', '/a/c/d', '../../../c/d', - ), - array( + ], + [ '/a/b/c//', '/a/b/c/', '../', - ), - array( + ], + [ '/a/b/c/', '/a/b/c//', './/', - ), - array( + ], + [ '/root/a/b/c/', '/root/x/b/c/', '../../../x/b/c/', - ), - array( + ], + [ '/a/b/c/d/', '/a', '../../../../a', - ), - array( + ], + [ '/special-chars/sp%20ce/1€/mäh/e=mc²', '/special-chars/sp%20ce/1€/<µ>/e=mc²', '../<µ>/e=mc²', - ), - array( + ], + [ 'not-rooted', 'dir/file', 'dir/file', - ), - array( + ], + [ '//dir/', '', '../../', - ), - array( + ], + [ '/dir/', '/dir/file:with-colon', './file:with-colon', - ), - array( + ], + [ '/dir/', '/dir/subdir/file:with-colon', 'subdir/file:with-colon', - ), - array( + ], + [ '/dir/', '/dir/:subdir/', './:subdir/', - ), - ); + ], + ]; } public function testFragmentsCanBeAppendedToUrls() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array('_fragment' => 'frag ment'), UrlGeneratorInterface::ABSOLUTE_PATH); + $url = $this->getGenerator($routes)->generate('test', ['_fragment' => 'frag ment'], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing#frag%20ment', $url); - $url = $this->getGenerator($routes)->generate('test', array('_fragment' => '0'), UrlGeneratorInterface::ABSOLUTE_PATH); + $url = $this->getGenerator($routes)->generate('test', ['_fragment' => '0'], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing#0', $url); } public function testFragmentsDoNotEscapeValidCharacters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array('_fragment' => '?/'), UrlGeneratorInterface::ABSOLUTE_PATH); + $url = $this->getGenerator($routes)->generate('test', ['_fragment' => '?/'], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing#?/', $url); } public function testFragmentsCanBeDefinedAsDefaults() { - $routes = $this->getRoutes('test', new Route('/testing', array('_fragment' => 'fragment'))); - $url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH); + $routes = $this->getRoutes('test', new Route('/testing', ['_fragment' => 'fragment'])); + $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing#fragment', $url); } - protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null) + protected function getGenerator(RouteCollection $routes, array $parameters = [], $logger = null) { $context = new RequestContext('/app.php'); foreach ($parameters as $key => $value) { diff --git a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php index dbb9b85b83..6eaacc78a5 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php @@ -33,7 +33,7 @@ class UrlMatcherTest extends TestCase public function testMethodNotAllowed() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('post'))); + $coll->add('foo', new Route('/foo', [], [], [], '', [], ['post'])); $matcher = $this->getUrlMatcher($coll); @@ -41,14 +41,14 @@ class UrlMatcherTest extends TestCase $matcher->match('/foo'); $this->fail(); } catch (MethodNotAllowedException $e) { - $this->assertEquals(array('POST'), $e->getAllowedMethods()); + $this->assertEquals(['POST'], $e->getAllowedMethods()); } } public function testMethodNotAllowedOnRoot() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/', array(), array(), array(), '', array(), array('GET'))); + $coll->add('foo', new Route('/', [], [], [], '', [], ['GET'])); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST')); @@ -56,14 +56,14 @@ class UrlMatcherTest extends TestCase $matcher->match('/'); $this->fail(); } catch (MethodNotAllowedException $e) { - $this->assertEquals(array('GET'), $e->getAllowedMethods()); + $this->assertEquals(['GET'], $e->getAllowedMethods()); } } public function testHeadAllowedWhenRequirementContainsGet() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('get'))); + $coll->add('foo', new Route('/foo', [], [], [], '', [], ['get'])); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'head')); $this->assertInternalType('array', $matcher->match('/foo')); @@ -72,8 +72,8 @@ class UrlMatcherTest extends TestCase public function testMethodNotAllowedAggregatesAllowedMethods() { $coll = new RouteCollection(); - $coll->add('foo1', new Route('/foo', array(), array(), array(), '', array(), array('post'))); - $coll->add('foo2', new Route('/foo', array(), array(), array(), '', array(), array('put', 'delete'))); + $coll->add('foo1', new Route('/foo', [], [], [], '', [], ['post'])); + $coll->add('foo2', new Route('/foo', [], [], [], '', [], ['put', 'delete'])); $matcher = $this->getUrlMatcher($coll); @@ -81,7 +81,7 @@ class UrlMatcherTest extends TestCase $matcher->match('/foo'); $this->fail(); } catch (MethodNotAllowedException $e) { - $this->assertEquals(array('POST', 'PUT', 'DELETE'), $e->getAllowedMethods()); + $this->assertEquals(['POST', 'PUT', 'DELETE'], $e->getAllowedMethods()); } } @@ -96,17 +96,17 @@ class UrlMatcherTest extends TestCase $this->fail(); } catch (ResourceNotFoundException $e) { } - $this->assertEquals(array('_route' => 'foo', 'bar' => 'baz'), $matcher->match('/foo/baz')); + $this->assertEquals(['_route' => 'foo', 'bar' => 'baz'], $matcher->match('/foo/baz')); // test that defaults are merged $collection = new RouteCollection(); - $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'))); + $collection->add('foo', new Route('/foo/{bar}', ['def' => 'test'])); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'def' => 'test'), $matcher->match('/foo/baz')); + $this->assertEquals(['_route' => 'foo', 'bar' => 'baz', 'def' => 'test'], $matcher->match('/foo/baz')); // test that route "method" is ignored if no method is given in the context $collection = new RouteCollection(); - $collection->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('get', 'head'))); + $collection->add('foo', new Route('/foo', [], [], [], '', [], ['get', 'head'])); $matcher = $this->getUrlMatcher($collection); $this->assertInternalType('array', $matcher->match('/foo')); @@ -126,24 +126,24 @@ class UrlMatcherTest extends TestCase // route with an optional variable as the first segment $collection = new RouteCollection(); - $collection->add('bar', new Route('/{bar}/foo', array('bar' => 'bar'), array('bar' => 'foo|bar'))); + $collection->add('bar', new Route('/{bar}/foo', ['bar' => 'bar'], ['bar' => 'foo|bar'])); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/bar/foo')); - $this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo/foo')); + $this->assertEquals(['_route' => 'bar', 'bar' => 'bar'], $matcher->match('/bar/foo')); + $this->assertEquals(['_route' => 'bar', 'bar' => 'foo'], $matcher->match('/foo/foo')); $collection = new RouteCollection(); - $collection->add('bar', new Route('/{bar}', array('bar' => 'bar'), array('bar' => 'foo|bar'))); + $collection->add('bar', new Route('/{bar}', ['bar' => 'bar'], ['bar' => 'foo|bar'])); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo')); - $this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/')); + $this->assertEquals(['_route' => 'bar', 'bar' => 'foo'], $matcher->match('/foo')); + $this->assertEquals(['_route' => 'bar', 'bar' => 'bar'], $matcher->match('/')); // route with only optional variables $collection = new RouteCollection(); - $collection->add('bar', new Route('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar'), array())); + $collection->add('bar', new Route('/{foo}/{bar}', ['foo' => 'foo', 'bar' => 'bar'], [])); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'bar', 'foo' => 'foo', 'bar' => 'bar'), $matcher->match('/')); - $this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'bar'), $matcher->match('/a')); - $this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'b'), $matcher->match('/a/b')); + $this->assertEquals(['_route' => 'bar', 'foo' => 'foo', 'bar' => 'bar'], $matcher->match('/')); + $this->assertEquals(['_route' => 'bar', 'foo' => 'a', 'bar' => 'bar'], $matcher->match('/a')); + $this->assertEquals(['_route' => 'bar', 'foo' => 'a', 'bar' => 'b'], $matcher->match('/a/b')); } public function testMatchWithPrefixes() @@ -154,7 +154,7 @@ class UrlMatcherTest extends TestCase $collection->addPrefix('/a'); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'foo', 'foo' => 'foo'), $matcher->match('/a/b/foo')); + $this->assertEquals(['_route' => 'foo', 'foo' => 'foo'], $matcher->match('/a/b/foo')); } public function testMatchWithDynamicPrefix() @@ -165,7 +165,7 @@ class UrlMatcherTest extends TestCase $collection->addPrefix('/{_locale}'); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo')); + $this->assertEquals(['_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'], $matcher->match('/fr/b/foo')); } public function testMatchSpecialRouteName() @@ -174,16 +174,16 @@ class UrlMatcherTest extends TestCase $collection->add('$péß^a|', new Route('/bar')); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => '$péß^a|'), $matcher->match('/bar')); + $this->assertEquals(['_route' => '$péß^a|'], $matcher->match('/bar')); } public function testMatchImportantVariable() { $collection = new RouteCollection(); - $collection->add('index', new Route('/index.{!_format}', array('_format' => 'xml'))); + $collection->add('index', new Route('/index.{!_format}', ['_format' => 'xml'])); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'index', '_format' => 'xml'), $matcher->match('/index.xml')); + $this->assertEquals(['_route' => 'index', '_format' => 'xml'], $matcher->match('/index.xml')); } /** @@ -202,20 +202,20 @@ class UrlMatcherTest extends TestCase { $collection = new RouteCollection(); $chars = '!"$%éà &\'()*+,./:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\[]^_`abcdefghijklmnopqrstuvwxyz{|}~-'; - $collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '['.preg_quote($chars).']+'), array('utf8' => true))); + $collection->add('foo', new Route('/{foo}/bar', [], ['foo' => '['.preg_quote($chars).']+'], ['utf8' => true])); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.rawurlencode($chars).'/bar')); - $this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.strtr($chars, array('%' => '%25')).'/bar')); + $this->assertEquals(['_route' => 'foo', 'foo' => $chars], $matcher->match('/'.rawurlencode($chars).'/bar')); + $this->assertEquals(['_route' => 'foo', 'foo' => $chars], $matcher->match('/'.strtr($chars, ['%' => '%25']).'/bar')); } public function testMatchWithDotMetacharacterInRequirements() { $collection = new RouteCollection(); - $collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '.+'))); + $collection->add('foo', new Route('/{foo}/bar', [], ['foo' => '.+'])); $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'foo', 'foo' => "\n"), $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched'); + $this->assertEquals(['_route' => 'foo', 'foo' => "\n"], $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched'); } public function testMatchOverriddenRoute() @@ -230,9 +230,9 @@ class UrlMatcherTest extends TestCase $matcher = $this->getUrlMatcher($collection); - $this->assertEquals(array('_route' => 'foo'), $matcher->match('/foo1')); + $this->assertEquals(['_route' => 'foo'], $matcher->match('/foo1')); $this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); - $this->assertEquals(array(), $matcher->match('/foo')); + $this->assertEquals([], $matcher->match('/foo')); } public function testMatchRegression() @@ -242,7 +242,7 @@ class UrlMatcherTest extends TestCase $coll->add('bar', new Route('/foo/bar/{foo}')); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('foo' => 'bar', '_route' => 'bar'), $matcher->match('/foo/bar/bar')); + $this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/foo/bar/bar')); $collection = new RouteCollection(); $collection->add('foo', new Route('/{bar}')); @@ -269,36 +269,36 @@ class UrlMatcherTest extends TestCase public function testDefaultRequirementForOptionalVariables() { $coll = new RouteCollection(); - $coll->add('test', new Route('/{page}.{_format}', array('page' => 'index', '_format' => 'html'))); + $coll->add('test', new Route('/{page}.{_format}', ['page' => 'index', '_format' => 'html'])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('page' => 'my-page', '_format' => 'xml', '_route' => 'test'), $matcher->match('/my-page.xml')); + $this->assertEquals(['page' => 'my-page', '_format' => 'xml', '_route' => 'test'], $matcher->match('/my-page.xml')); } public function testMatchingIsEager() { $coll = new RouteCollection(); - $coll->add('test', new Route('/{foo}-{bar}-', array(), array('foo' => '.+', 'bar' => '.+'))); + $coll->add('test', new Route('/{foo}-{bar}-', [], ['foo' => '.+', 'bar' => '.+'])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('foo' => 'text1-text2-text3', 'bar' => 'text4', '_route' => 'test'), $matcher->match('/text1-text2-text3-text4-')); + $this->assertEquals(['foo' => 'text1-text2-text3', 'bar' => 'text4', '_route' => 'test'], $matcher->match('/text1-text2-text3-text4-')); } public function testAdjacentVariables() { $coll = new RouteCollection(); - $coll->add('test', new Route('/{w}{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => 'y|Y'))); + $coll->add('test', new Route('/{w}{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => 'y|Y'])); $matcher = $this->getUrlMatcher($coll); // 'w' eagerly matches as much as possible and the other variables match the remaining chars. // This also shows that the variables w-z must all exclude the separating char (the dot '.' in this case) by default requirement. // Otherwise they would also consume '.xml' and _format would never match as it's an optional variable. - $this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'Y', 'z' => 'Z', '_format' => 'xml', '_route' => 'test'), $matcher->match('/wwwwwxYZ.xml')); + $this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'Y', 'z' => 'Z', '_format' => 'xml', '_route' => 'test'], $matcher->match('/wwwwwxYZ.xml')); // As 'y' has custom requirement and can only be of value 'y|Y', it will leave 'ZZZ' to variable z. // So with carefully chosen requirements adjacent variables, can be useful. - $this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'ZZZ', '_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxyZZZ')); + $this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'ZZZ', '_format' => 'html', '_route' => 'test'], $matcher->match('/wwwwwxyZZZ')); // z and _format are optional. - $this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z', '_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxy')); + $this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z', '_format' => 'html', '_route' => 'test'], $matcher->match('/wwwwwxy')); $this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); $matcher->match('/wxy.html'); @@ -307,11 +307,11 @@ class UrlMatcherTest extends TestCase public function testOptionalVariableWithNoRealSeparator() { $coll = new RouteCollection(); - $coll->add('test', new Route('/get{what}', array('what' => 'All'))); + $coll->add('test', new Route('/get{what}', ['what' => 'All'])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('what' => 'All', '_route' => 'test'), $matcher->match('/get')); - $this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSites')); + $this->assertEquals(['what' => 'All', '_route' => 'test'], $matcher->match('/get')); + $this->assertEquals(['what' => 'Sites', '_route' => 'test'], $matcher->match('/getSites')); // Usually the character in front of an optional parameter can be left out, e.g. with pattern '/get/{what}' just '/get' would match. // But here the 't' in 'get' is not a separating character, so it makes no sense to match without it. @@ -325,7 +325,7 @@ class UrlMatcherTest extends TestCase $coll->add('test', new Route('/get{what}Suffix')); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSitesSuffix')); + $this->assertEquals(['what' => 'Sites', '_route' => 'test'], $matcher->match('/getSitesSuffix')); } public function testDefaultRequirementOfVariable() @@ -334,7 +334,7 @@ class UrlMatcherTest extends TestCase $coll->add('test', new Route('/{page}.{_format}')); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('page' => 'index', '_format' => 'mobile.html', '_route' => 'test'), $matcher->match('/index.mobile.html')); + $this->assertEquals(['page' => 'index', '_format' => 'mobile.html', '_route' => 'test'], $matcher->match('/index.mobile.html')); } /** @@ -355,7 +355,7 @@ class UrlMatcherTest extends TestCase public function testDefaultRequirementOfVariableDisallowsNextSeparator() { $coll = new RouteCollection(); - $coll->add('test', new Route('/{page}.{_format}', array(), array('_format' => 'html|xml'))); + $coll->add('test', new Route('/{page}.{_format}', [], ['_format' => 'html|xml'])); $matcher = $this->getUrlMatcher($coll); $matcher->match('/do.t.html'); @@ -419,7 +419,7 @@ class UrlMatcherTest extends TestCase public function testSchemeRequirement() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https'))); + $coll->add('foo', new Route('/foo', [], [], [], '', ['https'])); $matcher = $this->getUrlMatcher($coll); $matcher->match('/foo'); } @@ -430,7 +430,7 @@ class UrlMatcherTest extends TestCase public function testSchemeRequirementForNonSafeMethod() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https'))); + $coll->add('foo', new Route('/foo', [], [], [], '', ['https'])); $context = new RequestContext(); $context->setMethod('POST'); @@ -441,10 +441,10 @@ class UrlMatcherTest extends TestCase public function testSamePathWithDifferentScheme() { $coll = new RouteCollection(); - $coll->add('https_route', new Route('/', array(), array(), array(), '', array('https'))); - $coll->add('http_route', new Route('/', array(), array(), array(), '', array('http'))); + $coll->add('https_route', new Route('/', [], [], [], '', ['https'])); + $coll->add('http_route', new Route('/', [], [], [], '', ['http'])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('_route' => 'http_route'), $matcher->match('/')); + $this->assertEquals(['_route' => 'http_route'], $matcher->match('/')); } /** @@ -470,7 +470,7 @@ class UrlMatcherTest extends TestCase $route->setCondition('request.getBaseUrl() == "/sub/front.php" and request.getPathInfo() == "/foo/bar"'); $coll->add('foo', $route); $matcher = $this->getUrlMatcher($coll, new RequestContext('/sub/front.php')); - $this->assertEquals(array('bar' => 'bar', '_route' => 'foo'), $matcher->match('/foo/bar')); + $this->assertEquals(['bar' => 'bar', '_route' => 'foo'], $matcher->match('/foo/bar')); } public function testDecodeOnce() @@ -479,7 +479,7 @@ class UrlMatcherTest extends TestCase $coll->add('foo', new Route('/foo/{foo}')); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('foo' => 'bar%23', '_route' => 'foo'), $matcher->match('/foo/bar%2523')); + $this->assertEquals(['foo' => 'bar%23', '_route' => 'foo'], $matcher->match('/foo/bar%2523')); } public function testCannotRelyOnPrefix() @@ -495,30 +495,30 @@ class UrlMatcherTest extends TestCase $coll->addCollection($subColl); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('_route' => 'bar'), $matcher->match('/new')); + $this->assertEquals(['_route' => 'bar'], $matcher->match('/new')); } public function testWithHost() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com')); + $coll->add('foo', new Route('/foo/{foo}', [], [], [], '{locale}.example.com')); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com')); - $this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar')); + $this->assertEquals(['foo' => 'bar', '_route' => 'foo', 'locale' => 'en'], $matcher->match('/foo/bar')); } public function testWithHostOnRouteCollection() { $coll = new RouteCollection(); $coll->add('foo', new Route('/foo/{foo}')); - $coll->add('bar', new Route('/bar/{foo}', array(), array(), array(), '{locale}.example.net')); + $coll->add('bar', new Route('/bar/{foo}', [], [], [], '{locale}.example.net')); $coll->setHost('{locale}.example.com'); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com')); - $this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar')); + $this->assertEquals(['foo' => 'bar', '_route' => 'foo', 'locale' => 'en'], $matcher->match('/foo/bar')); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com')); - $this->assertEquals(array('foo' => 'bar', '_route' => 'bar', 'locale' => 'en'), $matcher->match('/bar/bar')); + $this->assertEquals(['foo' => 'bar', '_route' => 'bar', 'locale' => 'en'], $matcher->match('/bar/bar')); } /** @@ -527,7 +527,7 @@ class UrlMatcherTest extends TestCase public function testWithOutHostHostDoesNotMatch() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com')); + $coll->add('foo', new Route('/foo/{foo}', [], [], [], '{locale}.example.com')); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'example.com')); $matcher->match('/foo/bar'); @@ -539,7 +539,7 @@ class UrlMatcherTest extends TestCase public function testPathIsCaseSensitive() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/locale', array(), array('locale' => 'EN|FR|DE'))); + $coll->add('foo', new Route('/locale', [], ['locale' => 'EN|FR|DE'])); $matcher = $this->getUrlMatcher($coll); $matcher->match('/en'); @@ -548,10 +548,10 @@ class UrlMatcherTest extends TestCase public function testHostIsCaseInsensitive() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/', array(), array('locale' => 'EN|FR|DE'), array(), '{locale}.example.com')); + $coll->add('foo', new Route('/', [], ['locale' => 'EN|FR|DE'], [], '{locale}.example.com')); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com')); - $this->assertEquals(array('_route' => 'foo', 'locale' => 'en'), $matcher->match('/')); + $this->assertEquals(['_route' => 'foo', 'locale' => 'en'], $matcher->match('/')); } /** @@ -584,9 +584,9 @@ class UrlMatcherTest extends TestCase $coll->addCollection($subColl); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('_route' => 'a'), $matcher->match('/p/a')); - $this->assertEquals(array('_route' => 'baz', 'baz' => 'p'), $matcher->match('/p')); - $this->assertEquals(array('_route' => 'buz'), $matcher->match('/prefix/buz')); + $this->assertEquals(['_route' => 'a'], $matcher->match('/p/a')); + $this->assertEquals(['_route' => 'baz', 'baz' => 'p'], $matcher->match('/p')); + $this->assertEquals(['_route' => 'buz'], $matcher->match('/prefix/buz')); } /** @@ -595,7 +595,7 @@ class UrlMatcherTest extends TestCase public function testSchemeAndMethodMismatch() { $coll = new RouteCollection(); - $coll->add('foo', new Route('/', array(), array(), array(), null, array('https'), array('POST'))); + $coll->add('foo', new Route('/', [], [], [], null, ['https'], ['POST'])); $matcher = $this->getUrlMatcher($coll); $matcher->match('/'); @@ -609,54 +609,54 @@ class UrlMatcherTest extends TestCase $coll->add('c', new Route('/a{a}')); $coll->add('d', (new Route('/b{a}'))->setCondition('false')); $coll->add('e', (new Route('/{b}{a}'))->setCondition('false')); - $coll->add('f', (new Route('/{b}{a}'))->setRequirements(array('b' => 'b'))); + $coll->add('f', (new Route('/{b}{a}'))->setRequirements(['b' => 'b'])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('_route' => 'c', 'a' => 'a'), $matcher->match('/aa')); - $this->assertEquals(array('_route' => 'f', 'b' => 'b', 'a' => 'a'), $matcher->match('/ba')); + $this->assertEquals(['_route' => 'c', 'a' => 'a'], $matcher->match('/aa')); + $this->assertEquals(['_route' => 'f', 'b' => 'b', 'a' => 'a'], $matcher->match('/ba')); } public function testUnicodeRoute() { $coll = new RouteCollection(); - $coll->add('a', new Route('/{a}', array(), array('a' => '.'), array('utf8' => false))); - $coll->add('b', new Route('/{a}', array(), array('a' => '.'), array('utf8' => true))); + $coll->add('a', new Route('/{a}', [], ['a' => '.'], ['utf8' => false])); + $coll->add('b', new Route('/{a}', [], ['a' => '.'], ['utf8' => true])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('_route' => 'b', 'a' => 'é'), $matcher->match('/é')); + $this->assertEquals(['_route' => 'b', 'a' => 'é'], $matcher->match('/é')); } public function testRequirementWithCapturingGroup() { $coll = new RouteCollection(); - $coll->add('a', new Route('/{a}/{b}', array(), array('a' => '(a|b)'))); + $coll->add('a', new Route('/{a}/{b}', [], ['a' => '(a|b)'])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('_route' => 'a', 'a' => 'a', 'b' => 'b'), $matcher->match('/a/b')); + $this->assertEquals(['_route' => 'a', 'a' => 'a', 'b' => 'b'], $matcher->match('/a/b')); } public function testDotAllWithCatchAll() { $coll = new RouteCollection(); - $coll->add('a', new Route('/{id}.html', array(), array('id' => '.+'))); - $coll->add('b', new Route('/{all}', array(), array('all' => '.+'))); + $coll->add('a', new Route('/{id}.html', [], ['id' => '.+'])); + $coll->add('b', new Route('/{all}', [], ['all' => '.+'])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('_route' => 'a', 'id' => 'foo/bar'), $matcher->match('/foo/bar.html')); + $this->assertEquals(['_route' => 'a', 'id' => 'foo/bar'], $matcher->match('/foo/bar.html')); } public function testHostPattern() { $coll = new RouteCollection(); - $coll->add('a', new Route('/{app}/{action}/{unused}', array(), array(), array(), '{host}')); + $coll->add('a', new Route('/{app}/{action}/{unused}', [], [], [], '{host}')); - $expected = array( + $expected = [ '_route' => 'a', 'app' => 'an_app', 'action' => 'an_action', 'unused' => 'unused', 'host' => 'foo', - ); + ]; $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo')); $this->assertEquals($expected, $matcher->match('/an_app/an_action/unused')); } @@ -664,8 +664,8 @@ class UrlMatcherTest extends TestCase public function testUtf8Prefix() { $coll = new RouteCollection(); - $coll->add('a', new Route('/é{foo}', array(), array(), array('utf8' => true))); - $coll->add('b', new Route('/è{bar}', array(), array(), array('utf8' => true))); + $coll->add('a', new Route('/é{foo}', [], [], ['utf8' => true])); + $coll->add('b', new Route('/è{bar}', [], [], ['utf8' => true])); $matcher = $this->getUrlMatcher($coll); $this->assertEquals('a', $matcher->match('/éo')['_route']); @@ -674,9 +674,9 @@ class UrlMatcherTest extends TestCase public function testUtf8AndMethodMatching() { $coll = new RouteCollection(); - $coll->add('a', new Route('/admin/api/list/{shortClassName}/{id}.{_format}', array(), array(), array('utf8' => true), '', array(), array('PUT'))); - $coll->add('b', new Route('/admin/api/package.{_format}', array(), array(), array(), '', array(), array('POST'))); - $coll->add('c', new Route('/admin/api/package.{_format}', array('_format' => 'json'), array(), array(), '', array(), array('GET'))); + $coll->add('a', new Route('/admin/api/list/{shortClassName}/{id}.{_format}', [], [], ['utf8' => true], '', [], ['PUT'])); + $coll->add('b', new Route('/admin/api/package.{_format}', [], [], [], '', [], ['POST'])); + $coll->add('c', new Route('/admin/api/package.{_format}', ['_format' => 'json'], [], [], '', [], ['GET'])); $matcher = $this->getUrlMatcher($coll); $this->assertEquals('c', $matcher->match('/admin/api/package.json')['_route']); @@ -685,7 +685,7 @@ class UrlMatcherTest extends TestCase public function testHostWithDot() { $coll = new RouteCollection(); - $coll->add('a', new Route('/foo', array(), array(), array(), 'foo.example.com')); + $coll->add('a', new Route('/foo', [], [], [], 'foo.example.com')); $coll->add('b', new Route('/bar/{baz}')); $matcher = $this->getUrlMatcher($coll); @@ -695,7 +695,7 @@ class UrlMatcherTest extends TestCase public function testSlashVariant() { $coll = new RouteCollection(); - $coll->add('a', new Route('/foo/{bar}', array(), array('bar' => '.*'))); + $coll->add('a', new Route('/foo/{bar}', [], ['bar' => '.*'])); $matcher = $this->getUrlMatcher($coll); $this->assertEquals('a', $matcher->match('/foo/')['_route']); @@ -704,54 +704,54 @@ class UrlMatcherTest extends TestCase public function testSlashVariant2() { $coll = new RouteCollection(); - $coll->add('a', new Route('/foo/{bar}/', array(), array('bar' => '.*'))); + $coll->add('a', new Route('/foo/{bar}/', [], ['bar' => '.*'])); $matcher = $this->getUrlMatcher($coll); - $this->assertEquals(array('_route' => 'a', 'bar' => 'bar'), $matcher->match('/foo/bar/')); + $this->assertEquals(['_route' => 'a', 'bar' => 'bar'], $matcher->match('/foo/bar/')); } public function testSlashWithVerb() { $coll = new RouteCollection(); - $coll->add('a', new Route('/{foo}', array(), array(), array(), '', array(), array('put', 'delete'))); + $coll->add('a', new Route('/{foo}', [], [], [], '', [], ['put', 'delete'])); $coll->add('b', new Route('/bar/')); $matcher = $this->getUrlMatcher($coll); - $this->assertSame(array('_route' => 'b'), $matcher->match('/bar/')); + $this->assertSame(['_route' => 'b'], $matcher->match('/bar/')); $coll = new RouteCollection(); - $coll->add('a', new Route('/dav/{foo<.*>?}', array(), array(), array(), '', array(), array('GET', 'OPTIONS'))); + $coll->add('a', new Route('/dav/{foo<.*>?}', [], [], [], '', [], ['GET', 'OPTIONS'])); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'OPTIONS')); - $expected = array( + $expected = [ '_route' => 'a', 'foo' => 'files/bar', - ); + ]; $this->assertEquals($expected, $matcher->match('/dav/files/bar/')); } public function testSlashAndVerbPrecedence() { $coll = new RouteCollection(); - $coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('post'))); - $coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('get'))); + $coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', [], [], [], '', [], ['post'])); + $coll->add('b', new Route('/api/customers/{customerId}/contactpersons', [], [], [], '', [], ['get'])); $matcher = $this->getUrlMatcher($coll); - $expected = array( + $expected = [ '_route' => 'b', 'customerId' => '123', - ); + ]; $this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons')); $coll = new RouteCollection(); - $coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('get'))); - $coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('post'))); + $coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', [], [], [], '', [], ['get'])); + $coll->add('b', new Route('/api/customers/{customerId}/contactpersons', [], [], [], '', [], ['post'])); $matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST')); - $expected = array( + $expected = [ '_route' => 'b', 'customerId' => '123', - ); + ]; $this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons')); } diff --git a/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php b/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php index d751e21046..123ecf7dd1 100644 --- a/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php @@ -31,32 +31,32 @@ class CsvEncoder implements EncoderInterface, DecoderInterface const AS_COLLECTION_KEY = 'as_collection'; const NO_HEADERS_KEY = 'no_headers'; - private $formulasStartCharacters = array('=', '-', '+', '@'); - private $defaultContext = array( + private $formulasStartCharacters = ['=', '-', '+', '@']; + private $defaultContext = [ self::DELIMITER_KEY => ',', self::ENCLOSURE_KEY => '"', self::ESCAPE_CHAR_KEY => '\\', self::ESCAPE_FORMULAS_KEY => false, - self::HEADERS_KEY => array(), + self::HEADERS_KEY => [], self::KEY_SEPARATOR_KEY => '.', self::NO_HEADERS_KEY => false, - ); + ]; /** * @param array $defaultContext */ - public function __construct($defaultContext = array(), string $enclosure = '"', string $escapeChar = '\\', string $keySeparator = '.', bool $escapeFormulas = false) + public function __construct($defaultContext = [], string $enclosure = '"', string $escapeChar = '\\', string $keySeparator = '.', bool $escapeFormulas = false) { if (!\is_array($defaultContext)) { @trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED); - $defaultContext = array( + $defaultContext = [ self::DELIMITER_KEY => (string) $defaultContext, self::ENCLOSURE_KEY => $enclosure, self::ESCAPE_CHAR_KEY => $escapeChar, self::KEY_SEPARATOR_KEY => $keySeparator, self::ESCAPE_FORMULAS_KEY => $escapeFormulas, - ); + ]; } $this->defaultContext = array_merge($this->defaultContext, $defaultContext); @@ -65,20 +65,20 @@ class CsvEncoder implements EncoderInterface, DecoderInterface /** * {@inheritdoc} */ - public function encode($data, $format, array $context = array()) + public function encode($data, $format, array $context = []) { $handle = fopen('php://temp,', 'w+'); if (!\is_array($data)) { - $data = array(array($data)); + $data = [[$data]]; } elseif (empty($data)) { - $data = array(array()); + $data = [[]]; } else { // Sequential arrays of arrays are considered as collections $i = 0; foreach ($data as $key => $value) { if ($i !== $key || !\is_array($value)) { - $data = array($data); + $data = [$data]; break; } @@ -89,7 +89,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface list($delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas) = $this->getCsvOptions($context); foreach ($data as &$value) { - $flattened = array(); + $flattened = []; $this->flatten($value, $flattened, $keySeparator, '', $escapeFormulas); $value = $flattened; } @@ -124,7 +124,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface /** * {@inheritdoc} */ - public function decode($data, $format, array $context = array()) + public function decode($data, $format, array $context = []) { $handle = fopen('php://temp', 'r+'); fwrite($handle, $data); @@ -132,8 +132,8 @@ class CsvEncoder implements EncoderInterface, DecoderInterface $headers = null; $nbHeaders = 0; - $headerCount = array(); - $result = array(); + $headerCount = []; + $result = []; list($delimiter, $enclosure, $escapeChar, $keySeparator) = $this->getCsvOptions($context); @@ -145,7 +145,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface if ($context[self::NO_HEADERS_KEY] ?? false) { for ($i = 0; $i < $nbCols; ++$i) { - $headers[] = array($i); + $headers[] = [$i]; } $headerCount = array_fill(0, $nbCols, 1); } else { @@ -159,7 +159,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface } } - $item = array(); + $item = []; for ($i = 0; ($i < $nbCols) && ($i < $nbHeaders); ++$i) { $depth = $headerCount[$i]; $arr = &$item; @@ -172,7 +172,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface } if (!isset($arr[$headers[$i][$j]])) { - $arr[$headers[$i][$j]] = array(); + $arr[$headers[$i][$j]] = []; } $arr = &$arr[$headers[$i][$j]]; @@ -238,7 +238,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface throw new InvalidArgumentException(sprintf('The "%s" context variable must be an array or null, given "%s".', self::HEADERS_KEY, \gettype($headers))); } - return array($delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas); + return [$delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas]; } /** @@ -246,8 +246,8 @@ class CsvEncoder implements EncoderInterface, DecoderInterface */ private function extractHeaders(array $data) { - $headers = array(); - $flippedHeaders = array(); + $headers = []; + $flippedHeaders = []; foreach ($data as $row) { $previousHeader = null; diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php index 04d98c5833..74235c46c1 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php @@ -316,9 +316,9 @@ a,b c,d CSV - , $this->encoder->encode(array(array('a', 'b'), array('c', 'd')), 'csv', array( + , $this->encoder->encode([['a', 'b'], ['c', 'd']], 'csv', [ CsvEncoder::NO_HEADERS_KEY => true, - ))); + ])); } public function testSupportsDecoding() @@ -495,13 +495,13 @@ CSV public function testDecodeWithoutHeader() { - $this->assertEquals(array(array('a', 'b'), array('c', 'd')), $this->encoder->decode(<<<'CSV' + $this->assertEquals([['a', 'b'], ['c', 'd']], $this->encoder->decode(<<<'CSV' a,b c,d CSV - , 'csv', array( + , 'csv', [ CsvEncoder::NO_HEADERS_KEY => true, - ))); + ])); } } diff --git a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php index 33599400c5..78c3fe9381 100644 --- a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php @@ -104,17 +104,17 @@ class XliffFileLoader implements LoaderInterface $catalogue->set((string) $source, $target, $domain); - $metadata = array( - 'file' => array( + $metadata = [ + 'file' => [ 'original' => (string) $fileAttributes['original'], - ), - ); + ], + ]; if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) { $metadata['notes'] = $notes; } if (isset($translation->target) && $translation->target->attributes()) { - $metadata['target-attributes'] = array(); + $metadata['target-attributes'] = []; foreach ($translation->target->attributes() as $key => $value) { $metadata['target-attributes'][$key] = (string) $value; } @@ -146,18 +146,18 @@ class XliffFileLoader implements LoaderInterface $catalogue->set((string) $source, $target, $domain); - $metadata = array(); + $metadata = []; if (isset($segment->target) && $segment->target->attributes()) { - $metadata['target-attributes'] = array(); + $metadata['target-attributes'] = []; foreach ($segment->target->attributes() as $key => $value) { $metadata['target-attributes'][$key] = (string) $value; } } if (isset($unit->notes)) { - $metadata['notes'] = array(); + $metadata['notes'] = []; foreach ($unit->notes->note as $noteNode) { - $note = array(); + $note = []; foreach ($noteNode->attributes() as $key => $value) { $note[$key] = (string) $value; } @@ -185,7 +185,7 @@ class XliffFileLoader implements LoaderInterface private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, string $encoding = null): array { - $notes = array(); + $notes = []; if (null === $noteElement) { return $notes; @@ -194,7 +194,7 @@ class XliffFileLoader implements LoaderInterface /** @var \SimpleXMLElement $xmlNote */ foreach ($noteElement as $xmlNote) { $noteAttributes = $xmlNote->attributes(); - $note = array('content' => $this->utf8ToCharset((string) $xmlNote, $encoding)); + $note = ['content' => $this->utf8ToCharset((string) $xmlNote, $encoding)]; if (isset($noteAttributes['priority'])) { $note['priority'] = (int) $noteAttributes['priority']; } diff --git a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php index cf21c8227f..f475c065b2 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php @@ -24,8 +24,8 @@ class XliffFileLoaderTest extends TestCase $catalogue = $loader->load($resource, 'en', 'domain1'); $this->assertEquals('en', $catalogue->getLocale()); - $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); - $this->assertSame(array(), libxml_get_errors()); + $this->assertEquals([new FileResource($resource)], $catalogue->getResources()); + $this->assertSame([], libxml_get_errors()); $this->assertContainsOnly('string', $catalogue->all('domain1')); } @@ -33,15 +33,15 @@ class XliffFileLoaderTest extends TestCase { $internalErrors = libxml_use_internal_errors(true); - $this->assertSame(array(), libxml_get_errors()); + $this->assertSame([], libxml_get_errors()); $loader = new XliffFileLoader(); $resource = __DIR__.'/../fixtures/resources.xlf'; $catalogue = $loader->load($resource, 'en', 'domain1'); $this->assertEquals('en', $catalogue->getLocale()); - $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); - $this->assertSame(array(), libxml_get_errors()); + $this->assertEquals([new FileResource($resource)], $catalogue->getResources()); + $this->assertSame([], libxml_get_errors()); libxml_clear_errors(); libxml_use_internal_errors($internalErrors); @@ -58,7 +58,7 @@ class XliffFileLoaderTest extends TestCase libxml_disable_entity_loader($disableEntities); $this->assertEquals('en', $catalogue->getLocale()); - $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + $this->assertEquals([new FileResource($resource)], $catalogue->getResources()); } public function testLoadWithResname() @@ -66,7 +66,7 @@ class XliffFileLoaderTest extends TestCase $loader = new XliffFileLoader(); $catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1'); - $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'), $catalogue->all('domain1')); + $this->assertEquals(['foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'], $catalogue->all('domain1')); } public function testIncompleteResource() @@ -74,7 +74,7 @@ class XliffFileLoaderTest extends TestCase $loader = new XliffFileLoader(); $catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1'); - $this->assertEquals(array('foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'), $catalogue->all('domain1')); + $this->assertEquals(['foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'], $catalogue->all('domain1')); } public function testEncoding() @@ -85,13 +85,13 @@ class XliffFileLoaderTest extends TestCase $this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1')); $this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1')); $this->assertEquals( - array( - 'notes' => array(array('content' => utf8_decode('bäz'))), + [ + 'notes' => [['content' => utf8_decode('bäz')]], 'id' => '1', - 'file' => array( + 'file' => [ 'original' => 'file.ext', - ), - ), + ], + ], $catalogue->getMetadata('foo', 'domain1') ); } @@ -174,38 +174,38 @@ class XliffFileLoaderTest extends TestCase $catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1'); $this->assertEquals( - array( - 'notes' => array(array('priority' => 1, 'content' => 'foo')), + [ + 'notes' => [['priority' => 1, 'content' => 'foo']], 'id' => '1', - 'file' => array( + 'file' => [ 'original' => 'file.ext', - ), - ), + ], + ], $catalogue->getMetadata('foo', 'domain1') ); // message without target $this->assertEquals( - array( - 'notes' => array(array('content' => 'bar', 'from' => 'foo')), + [ + 'notes' => [['content' => 'bar', 'from' => 'foo']], 'id' => '2', - 'file' => array( + 'file' => [ 'original' => 'file.ext', - ), - ), + ], + ], $catalogue->getMetadata('extra', 'domain1') ); // message with empty target $this->assertEquals( - array( - 'notes' => array( - array('content' => 'baz'), - array('priority' => 2, 'from' => 'bar', 'content' => 'qux'), - ), + [ + 'notes' => [ + ['content' => 'baz'], + ['priority' => 2, 'from' => 'bar', 'content' => 'qux'], + ], 'id' => '123', - 'file' => array( + 'file' => [ 'original' => 'file.ext', - ), - ), + ], + ], $catalogue->getMetadata('key', 'domain1') ); } @@ -217,15 +217,15 @@ class XliffFileLoaderTest extends TestCase $catalogue = $loader->load($resource, 'en', 'domain1'); $this->assertEquals('en', $catalogue->getLocale()); - $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); - $this->assertSame(array(), libxml_get_errors()); + $this->assertEquals([new FileResource($resource)], $catalogue->getResources()); + $this->assertSame([], libxml_get_errors()); $domains = $catalogue->all(); $this->assertCount(3, $domains['domain1']); $this->assertContainsOnly('string', $catalogue->all('domain1')); // target attributes - $this->assertEquals(array('target-attributes' => array('order' => 1)), $catalogue->getMetadata('bar', 'domain1')); + $this->assertEquals(['target-attributes' => ['order' => 1]], $catalogue->getMetadata('bar', 'domain1')); } public function testLoadVersion2WithNoteMeta() @@ -235,8 +235,8 @@ class XliffFileLoaderTest extends TestCase $catalogue = $loader->load($resource, 'en', 'domain1'); $this->assertEquals('en', $catalogue->getLocale()); - $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); - $this->assertSame(array(), libxml_get_errors()); + $this->assertEquals([new FileResource($resource)], $catalogue->getResources()); + $this->assertSame([], libxml_get_errors()); // test for "foo" metadata $this->assertTrue($catalogue->defines('foo', 'domain1')); @@ -275,7 +275,7 @@ class XliffFileLoaderTest extends TestCase $catalog = $loader->load($resource, 'en', 'domain1'); $this->assertSame('en', $catalog->getLocale()); - $this->assertEquals(array(new FileResource($resource)), $catalog->getResources()); + $this->assertEquals([new FileResource($resource)], $catalog->getResources()); $this->assertFalse(libxml_get_last_error()); // test for "foo" metadata @@ -303,22 +303,22 @@ class XliffFileLoaderTest extends TestCase $catalogue = $loader->load(__DIR__.'/../fixtures/resources-multi-files.xlf', 'en', 'domain1'); $this->assertEquals( - array( + [ 'id' => '1', - 'file' => array( + 'file' => [ 'original' => 'file.ext', - ), - ), + ], + ], $catalogue->getMetadata('foo', 'domain1') ); $this->assertEquals( - array( - 'notes' => array(array('content' => 'note')), + [ + 'notes' => [['content' => 'note']], 'id' => '4', - 'file' => array( + 'file' => [ 'original' => 'otherfile.ext', - ), - ), + ], + ], $catalogue->getMetadata('test', 'domain1') ); } diff --git a/src/Symfony/Component/Validator/Constraints/BicValidator.php b/src/Symfony/Component/Validator/Constraints/BicValidator.php index c58f8ac7de..3036d200e0 100644 --- a/src/Symfony/Component/Validator/Constraints/BicValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BicValidator.php @@ -29,7 +29,7 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException; */ class BicValidator extends ConstraintValidator { - private const BIC_COUNTRY_TO_IBAN_COUNTRY_MAP = array( + private const BIC_COUNTRY_TO_IBAN_COUNTRY_MAP = [ // Reference: https://www.ecbs.org/iban/france-bank-account-number.html 'GF' => 'FR', // French Guiana 'PF' => 'FR', // French Polynesia @@ -46,7 +46,7 @@ class BicValidator extends ConstraintValidator 'IM' => 'GB', // Isle of Man 'GG' => 'GB', // Guernsey 'VG' => 'GB', // British Virgin Islands - ); + ]; private $propertyAccessor; diff --git a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php index 0a3c06c145..dcc5ad0cb8 100644 --- a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php @@ -27,66 +27,66 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException; */ class CardSchemeValidator extends ConstraintValidator { - protected $schemes = array( + protected $schemes = [ // American Express card numbers start with 34 or 37 and have 15 digits. - 'AMEX' => array( + 'AMEX' => [ '/^3[47][0-9]{13}$/', - ), + ], // China UnionPay cards start with 62 and have between 16 and 19 digits. // Please note that these cards do not follow Luhn Algorithm as a checksum. - 'CHINA_UNIONPAY' => array( + 'CHINA_UNIONPAY' => [ '/^62[0-9]{14,17}$/', - ), + ], // Diners Club card numbers begin with 300 through 305, 36 or 38. All have 14 digits. // There are Diners Club cards that begin with 5 and have 16 digits. // These are a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard. - 'DINERS' => array( + 'DINERS' => [ '/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/', - ), + ], // Discover card numbers begin with 6011, 622126 through 622925, 644 through 649 or 65. // All have 16 digits. - 'DISCOVER' => array( + 'DISCOVER' => [ '/^6011[0-9]{12}$/', '/^64[4-9][0-9]{13}$/', '/^65[0-9]{14}$/', '/^622(12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|91[0-9]|92[0-5])[0-9]{10}$/', - ), + ], // InstaPayment cards begin with 637 through 639 and have 16 digits. - 'INSTAPAYMENT' => array( + 'INSTAPAYMENT' => [ '/^63[7-9][0-9]{13}$/', - ), + ], // JCB cards beginning with 2131 or 1800 have 15 digits. // JCB cards beginning with 35 have 16 digits. - 'JCB' => array( + 'JCB' => [ '/^(?:2131|1800|35[0-9]{3})[0-9]{11}$/', - ), + ], // Laser cards begin with either 6304, 6706, 6709 or 6771 and have between 16 and 19 digits. - 'LASER' => array( + 'LASER' => [ '/^(6304|670[69]|6771)[0-9]{12,15}$/', - ), + ], // Maestro international cards begin with 675900..675999 and have between 12 and 19 digits. // Maestro UK cards begin with either 500000..509999 or 560000..699999 and have between 12 and 19 digits. - 'MAESTRO' => array( + 'MAESTRO' => [ '/^(6759[0-9]{2})[0-9]{6,13}$/', '/^(50[0-9]{4})[0-9]{6,13}$/', '/^5[6-9][0-9]{10,17}$/', '/^6[0-9]{11,18}$/', - ), + ], // All MasterCard numbers start with the numbers 51 through 55. All have 16 digits. // October 2016 MasterCard numbers can also start with 222100 through 272099. - 'MASTERCARD' => array( + 'MASTERCARD' => [ '/^5[1-5][0-9]{14}$/', '/^2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12})$/', - ), + ], // All UATP card numbers start with a 1 and have a length of 15 digits. - 'UATP' => array( + 'UATP' => [ '/^1[0-9]{14}$/', - ), + ], // All Visa card numbers start with a 4 and have a length of 13, 16, or 19 digits. - 'VISA' => array( + 'VISA' => [ '/^4([0-9]{12}|[0-9]{15}|[0-9]{18})$/', - ), - ); + ], + ]; /** * Validates a creditcard belongs to a specified scheme. diff --git a/src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php index d7dc469479..174bbb2863 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php @@ -39,7 +39,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase public function testValidComparisonToPropertyPath() { - $constraint = new Bic(array('ibanPropertyPath' => 'value')); + $constraint = new Bic(['ibanPropertyPath' => 'value']); $object = new BicComparisonTestClass('FR14 2004 1010 0505 0001 3M02 606'); @@ -52,9 +52,9 @@ class BicValidatorTest extends ConstraintValidatorTestCase public function testValidComparisonToPropertyPathOnArray() { - $constraint = new Bic(array('ibanPropertyPath' => '[root][value]')); + $constraint = new Bic(['ibanPropertyPath' => '[root][value]']); - $this->setObject(array('root' => array('value' => 'FR14 2004 1010 0505 0001 3M02 606'))); + $this->setObject(['root' => ['value' => 'FR14 2004 1010 0505 0001 3M02 606']]); $this->validator->validate('SOGEFRPP', $constraint); @@ -63,7 +63,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase public function testInvalidComparisonToPropertyPath() { - $constraint = new Bic(array('ibanPropertyPath' => 'value')); + $constraint = new Bic(['ibanPropertyPath' => 'value']); $constraint->ibanMessage = 'Constraint Message'; $object = new BicComparisonTestClass('FR14 2004 1010 0505 0001 3M02 606'); @@ -81,7 +81,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase public function testValidComparisonToValue() { - $constraint = new Bic(array('iban' => 'FR14 2004 1010 0505 0001 3M02 606')); + $constraint = new Bic(['iban' => 'FR14 2004 1010 0505 0001 3M02 606']); $constraint->ibanMessage = 'Constraint Message'; $this->validator->validate('SOGEFRPP', $constraint); @@ -91,7 +91,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase public function testInvalidComparisonToValue() { - $constraint = new Bic(array('iban' => 'FR14 2004 1010 0505 0001 3M02 606')); + $constraint = new Bic(['iban' => 'FR14 2004 1010 0505 0001 3M02 606']); $constraint->ibanMessage = 'Constraint Message'; $this->validator->validate('UNCRIT2B912', $constraint); @@ -105,7 +105,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase public function testNoViolationOnNullObjectWithPropertyPath() { - $constraint = new Bic(array('ibanPropertyPath' => 'propertyPath')); + $constraint = new Bic(['ibanPropertyPath' => 'propertyPath']); $this->setObject(null); @@ -120,15 +120,15 @@ class BicValidatorTest extends ConstraintValidatorTestCase */ public function testThrowsConstraintExceptionIfBothValueAndPropertyPath() { - new Bic(array( + new Bic([ 'iban' => 'value', 'ibanPropertyPath' => 'propertyPath', - )); + ]); } public function testInvalidValuePath() { - $constraint = new Bic(array('ibanPropertyPath' => 'foo')); + $constraint = new Bic(['ibanPropertyPath' => 'foo']); if (method_exists($this, 'expectException')) { $this->expectException(ConstraintDefinitionException::class); @@ -230,7 +230,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase */ public function testValidBicSpecialCases(string $bic, string $iban) { - $constraint = new Bic(array('iban' => $iban)); + $constraint = new Bic(['iban' => $iban]); $this->validator->validate($bic, $constraint); $this->assertNoViolation(); @@ -239,22 +239,22 @@ class BicValidatorTest extends ConstraintValidatorTestCase public function getValidBicSpecialCases() { // FR related special cases - yield array('BNPAGFGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPAPFGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPATFGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPAGPGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPAMQGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPAYTGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPANCGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPAREGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPAPMGX', 'FR14 2004 1010 0505 0001 3M02 606'); - yield array('BNPAWFGX', 'FR14 2004 1010 0505 0001 3M02 606'); + yield ['BNPAGFGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPAPFGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPATFGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPAGPGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPAMQGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPAYTGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPANCGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPAREGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPAPMGX', 'FR14 2004 1010 0505 0001 3M02 606']; + yield ['BNPAWFGX', 'FR14 2004 1010 0505 0001 3M02 606']; // GB related special cases - yield array('BARCJESA', 'GB12 CPBK 0892 9965 0449 911'); - yield array('BARCIMSA', 'GB12 CPBK 0892 9965 0449 911'); - yield array('BARCGGSA', 'GB12 CPBK 0892 9965 0449 911'); - yield array('BARCVGSA', 'GB12 CPBK 0892 9965 0449 911'); + yield ['BARCJESA', 'GB12 CPBK 0892 9965 0449 911']; + yield ['BARCIMSA', 'GB12 CPBK 0892 9965 0449 911']; + yield ['BARCGGSA', 'GB12 CPBK 0892 9965 0449 911']; + yield ['BARCVGSA', 'GB12 CPBK 0892 9965 0449 911']; } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php index fccee9e0ab..24c23109f4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php @@ -24,14 +24,14 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase public function testNullIsValid() { - $this->validator->validate(null, new CardScheme(array('schemes' => array()))); + $this->validator->validate(null, new CardScheme(['schemes' => []])); $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->validator->validate('', new CardScheme(array('schemes' => array()))); + $this->validator->validate('', new CardScheme(['schemes' => []])); $this->assertNoViolation(); } @@ -41,7 +41,7 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase */ public function testValidNumbers($scheme, $number) { - $this->validator->validate($number, new CardScheme(array('schemes' => $scheme))); + $this->validator->validate($number, new CardScheme(['schemes' => $scheme])); $this->assertNoViolation(); } @@ -51,10 +51,10 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase */ public function testInvalidNumbers($scheme, $number, $code) { - $constraint = new CardScheme(array( + $constraint = new CardScheme([ 'schemes' => $scheme, 'message' => 'myMessage', - )); + ]); $this->validator->validate($number, $constraint); @@ -66,75 +66,75 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase public function getValidNumbers() { - return array( - array('AMEX', '378282246310005'), - array('AMEX', '371449635398431'), - array('AMEX', '378734493671000'), - array('AMEX', '347298508610146'), - array('CHINA_UNIONPAY', '6228888888888888'), - array('CHINA_UNIONPAY', '62288888888888888'), - array('CHINA_UNIONPAY', '622888888888888888'), - array('CHINA_UNIONPAY', '6228888888888888888'), - array('DINERS', '30569309025904'), - array('DINERS', '36088894118515'), - array('DINERS', '38520000023237'), - array('DISCOVER', '6011111111111117'), - array('DISCOVER', '6011000990139424'), - array('INSTAPAYMENT', '6372476031350068'), - array('INSTAPAYMENT', '6385537775789749'), - array('INSTAPAYMENT', '6393440808445746'), - array('JCB', '3530111333300000'), - array('JCB', '3566002020360505'), - array('JCB', '213112345678901'), - array('JCB', '180012345678901'), - array('LASER', '6304678107004080'), - array('LASER', '6706440607428128629'), - array('LASER', '6771656738314582216'), - array('MAESTRO', '6759744069209'), - array('MAESTRO', '5020507657408074712'), - array('MAESTRO', '5612559223580173965'), - array('MAESTRO', '6759744069209'), - array('MAESTRO', '6594371785970435599'), - array('MASTERCARD', '5555555555554444'), - array('MASTERCARD', '5105105105105100'), - array('MASTERCARD', '2221005555554444'), - array('MASTERCARD', '2230000000000000'), - array('MASTERCARD', '2300000000000000'), - array('MASTERCARD', '2699999999999999'), - array('MASTERCARD', '2709999999999999'), - array('MASTERCARD', '2720995105105100'), - array('UATP', '110165309696173'), - array('VISA', '4111111111111111'), - array('VISA', '4012888888881881'), - array('VISA', '4222222222222'), - array('VISA', '4917610000000000003'), - array(array('AMEX', 'VISA'), '4111111111111111'), - array(array('AMEX', 'VISA'), '378282246310005'), - array(array('JCB', 'MASTERCARD'), '5105105105105100'), - array(array('VISA', 'MASTERCARD'), '5105105105105100'), - ); + return [ + ['AMEX', '378282246310005'], + ['AMEX', '371449635398431'], + ['AMEX', '378734493671000'], + ['AMEX', '347298508610146'], + ['CHINA_UNIONPAY', '6228888888888888'], + ['CHINA_UNIONPAY', '62288888888888888'], + ['CHINA_UNIONPAY', '622888888888888888'], + ['CHINA_UNIONPAY', '6228888888888888888'], + ['DINERS', '30569309025904'], + ['DINERS', '36088894118515'], + ['DINERS', '38520000023237'], + ['DISCOVER', '6011111111111117'], + ['DISCOVER', '6011000990139424'], + ['INSTAPAYMENT', '6372476031350068'], + ['INSTAPAYMENT', '6385537775789749'], + ['INSTAPAYMENT', '6393440808445746'], + ['JCB', '3530111333300000'], + ['JCB', '3566002020360505'], + ['JCB', '213112345678901'], + ['JCB', '180012345678901'], + ['LASER', '6304678107004080'], + ['LASER', '6706440607428128629'], + ['LASER', '6771656738314582216'], + ['MAESTRO', '6759744069209'], + ['MAESTRO', '5020507657408074712'], + ['MAESTRO', '5612559223580173965'], + ['MAESTRO', '6759744069209'], + ['MAESTRO', '6594371785970435599'], + ['MASTERCARD', '5555555555554444'], + ['MASTERCARD', '5105105105105100'], + ['MASTERCARD', '2221005555554444'], + ['MASTERCARD', '2230000000000000'], + ['MASTERCARD', '2300000000000000'], + ['MASTERCARD', '2699999999999999'], + ['MASTERCARD', '2709999999999999'], + ['MASTERCARD', '2720995105105100'], + ['UATP', '110165309696173'], + ['VISA', '4111111111111111'], + ['VISA', '4012888888881881'], + ['VISA', '4222222222222'], + ['VISA', '4917610000000000003'], + [['AMEX', 'VISA'], '4111111111111111'], + [['AMEX', 'VISA'], '378282246310005'], + [['JCB', 'MASTERCARD'], '5105105105105100'], + [['VISA', 'MASTERCARD'], '5105105105105100'], + ]; } public function getInvalidNumbers() { - return array( - array('VISA', '42424242424242424242', CardScheme::INVALID_FORMAT_ERROR), - array('AMEX', '357298508610146', CardScheme::INVALID_FORMAT_ERROR), - array('DINERS', '31569309025904', CardScheme::INVALID_FORMAT_ERROR), - array('DINERS', '37088894118515', CardScheme::INVALID_FORMAT_ERROR), - array('INSTAPAYMENT', '6313440808445746', CardScheme::INVALID_FORMAT_ERROR), - array('CHINA_UNIONPAY', '622888888888888', CardScheme::INVALID_FORMAT_ERROR), - array('CHINA_UNIONPAY', '62288888888888888888', CardScheme::INVALID_FORMAT_ERROR), - array('AMEX', '30569309025904', CardScheme::INVALID_FORMAT_ERROR), // DINERS number - array('AMEX', 'invalid', CardScheme::NOT_NUMERIC_ERROR), // A string - array('AMEX', 0, CardScheme::INVALID_FORMAT_ERROR), // a lone number - array('AMEX', '0', CardScheme::INVALID_FORMAT_ERROR), // a lone number - array('AMEX', '000000000000', CardScheme::INVALID_FORMAT_ERROR), // a lone number - array('DINERS', '3056930', CardScheme::INVALID_FORMAT_ERROR), // only first part of the number - array('DISCOVER', '1117', CardScheme::INVALID_FORMAT_ERROR), // only last 4 digits - array('MASTERCARD', '2721001234567890', CardScheme::INVALID_FORMAT_ERROR), // Not assigned yet - array('MASTERCARD', '2220991234567890', CardScheme::INVALID_FORMAT_ERROR), // Not assigned yet - array('UATP', '11016530969617', CardScheme::INVALID_FORMAT_ERROR), // invalid length - ); + return [ + ['VISA', '42424242424242424242', CardScheme::INVALID_FORMAT_ERROR], + ['AMEX', '357298508610146', CardScheme::INVALID_FORMAT_ERROR], + ['DINERS', '31569309025904', CardScheme::INVALID_FORMAT_ERROR], + ['DINERS', '37088894118515', CardScheme::INVALID_FORMAT_ERROR], + ['INSTAPAYMENT', '6313440808445746', CardScheme::INVALID_FORMAT_ERROR], + ['CHINA_UNIONPAY', '622888888888888', CardScheme::INVALID_FORMAT_ERROR], + ['CHINA_UNIONPAY', '62288888888888888888', CardScheme::INVALID_FORMAT_ERROR], + ['AMEX', '30569309025904', CardScheme::INVALID_FORMAT_ERROR], // DINERS number + ['AMEX', 'invalid', CardScheme::NOT_NUMERIC_ERROR], // A string + ['AMEX', 0, CardScheme::INVALID_FORMAT_ERROR], // a lone number + ['AMEX', '0', CardScheme::INVALID_FORMAT_ERROR], // a lone number + ['AMEX', '000000000000', CardScheme::INVALID_FORMAT_ERROR], // a lone number + ['DINERS', '3056930', CardScheme::INVALID_FORMAT_ERROR], // only first part of the number + ['DISCOVER', '1117', CardScheme::INVALID_FORMAT_ERROR], // only last 4 digits + ['MASTERCARD', '2721001234567890', CardScheme::INVALID_FORMAT_ERROR], // Not assigned yet + ['MASTERCARD', '2220991234567890', CardScheme::INVALID_FORMAT_ERROR], // Not assigned yet + ['UATP', '11016530969617', CardScheme::INVALID_FORMAT_ERROR], // invalid length + ]; } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php index 1587392b60..b67846f878 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php @@ -24,14 +24,14 @@ class RegexValidatorTest extends ConstraintValidatorTestCase public function testNullIsValid() { - $this->validator->validate(null, new Regex(array('pattern' => '/^[0-9]+$/'))); + $this->validator->validate(null, new Regex(['pattern' => '/^[0-9]+$/'])); $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->validator->validate('', new Regex(array('pattern' => '/^[0-9]+$/'))); + $this->validator->validate('', new Regex(['pattern' => '/^[0-9]+$/'])); $this->assertNoViolation(); } @@ -41,7 +41,7 @@ class RegexValidatorTest extends ConstraintValidatorTestCase */ public function testExpectsStringCompatibleType() { - $this->validator->validate(new \stdClass(), new Regex(array('pattern' => '/^[0-9]+$/'))); + $this->validator->validate(new \stdClass(), new Regex(['pattern' => '/^[0-9]+$/'])); } /** @@ -49,7 +49,7 @@ class RegexValidatorTest extends ConstraintValidatorTestCase */ public function testValidValues($value) { - $constraint = new Regex(array('pattern' => '/^[0-9]+$/')); + $constraint = new Regex(['pattern' => '/^[0-9]+$/']); $this->validator->validate($value, $constraint); $this->assertNoViolation(); @@ -57,18 +57,18 @@ class RegexValidatorTest extends ConstraintValidatorTestCase public function getValidValues() { - return array( - array(0), - array('0'), - array('090909'), - array(90909), - array(new class() { + return [ + [0], + ['0'], + ['090909'], + [90909], + [new class() { public function __toString() { return '090909'; } - }), - ); + }], + ]; } /** @@ -76,10 +76,10 @@ class RegexValidatorTest extends ConstraintValidatorTestCase */ public function testInvalidValues($value) { - $constraint = new Regex(array( + $constraint = new Regex([ 'pattern' => '/^[0-9]+$/', 'message' => 'myMessage', - )); + ]); $this->validator->validate($value, $constraint); @@ -91,15 +91,15 @@ class RegexValidatorTest extends ConstraintValidatorTestCase public function getInvalidValues() { - return array( - array('abcd'), - array('090foo'), - array(new class() { + return [ + ['abcd'], + ['090foo'], + [new class() { public function __toString() { return 'abcd'; } - }), - ); + }], + ]; } } diff --git a/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php b/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php index 85de5b5967..5d9b80de2a 100644 --- a/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php @@ -81,17 +81,17 @@ class ResourceCaster $pin = base64_decode(implode('', $pin)); $pin = base64_encode(hash('sha256', $pin, true)); - $a += array( - 'subject' => new EnumStub(array_intersect_key($info['subject'], array('organizationName' => true, 'commonName' => true))), - 'issuer' => new EnumStub(array_intersect_key($info['issuer'], array('organizationName' => true, 'commonName' => true))), + $a += [ + 'subject' => new EnumStub(array_intersect_key($info['subject'], ['organizationName' => true, 'commonName' => true])), + 'issuer' => new EnumStub(array_intersect_key($info['issuer'], ['organizationName' => true, 'commonName' => true])), 'expiry' => new ConstStub(date(\DateTime::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']), - 'fingerprint' => new EnumStub(array( + 'fingerprint' => new EnumStub([ 'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)), 'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)), 'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)), 'pin-sha256' => new ConstStub($pin), - )), - ); + ]), + ]; return $a; } diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index f55b2a1c67..8d0525062b 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -21,134 +21,134 @@ use Symfony\Component\VarDumper\Exception\ThrowingCasterException; */ abstract class AbstractCloner implements ClonerInterface { - public static $defaultCasters = array( - '__PHP_Incomplete_Class' => array('Symfony\Component\VarDumper\Caster\Caster', 'castPhpIncompleteClass'), + public static $defaultCasters = [ + '__PHP_Incomplete_Class' => ['Symfony\Component\VarDumper\Caster\Caster', 'castPhpIncompleteClass'], - 'Symfony\Component\VarDumper\Caster\CutStub' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'), - 'Symfony\Component\VarDumper\Caster\CutArrayStub' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'castCutArray'), - 'Symfony\Component\VarDumper\Caster\ConstStub' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'), - 'Symfony\Component\VarDumper\Caster\EnumStub' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'castEnum'), + 'Symfony\Component\VarDumper\Caster\CutStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'], + 'Symfony\Component\VarDumper\Caster\CutArrayStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castCutArray'], + 'Symfony\Component\VarDumper\Caster\ConstStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'], + 'Symfony\Component\VarDumper\Caster\EnumStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castEnum'], - 'Closure' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClosure'), - 'Generator' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castGenerator'), - 'ReflectionType' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castType'), - 'ReflectionGenerator' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castReflectionGenerator'), - 'ReflectionClass' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClass'), - 'ReflectionFunctionAbstract' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castFunctionAbstract'), - 'ReflectionMethod' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castMethod'), - 'ReflectionParameter' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castParameter'), - 'ReflectionProperty' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castProperty'), - 'ReflectionExtension' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castExtension'), - 'ReflectionZendExtension' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castZendExtension'), + 'Closure' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClosure'], + 'Generator' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castGenerator'], + 'ReflectionType' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castType'], + 'ReflectionGenerator' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castReflectionGenerator'], + 'ReflectionClass' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClass'], + 'ReflectionFunctionAbstract' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castFunctionAbstract'], + 'ReflectionMethod' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castMethod'], + 'ReflectionParameter' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castParameter'], + 'ReflectionProperty' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castProperty'], + 'ReflectionExtension' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castExtension'], + 'ReflectionZendExtension' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castZendExtension'], - 'Doctrine\Common\Persistence\ObjectManager' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'), - 'Doctrine\Common\Proxy\Proxy' => array('Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'), - 'Doctrine\ORM\Proxy\Proxy' => array('Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'), - 'Doctrine\ORM\PersistentCollection' => array('Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'), + 'Doctrine\Common\Persistence\ObjectManager' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], + 'Doctrine\Common\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'], + 'Doctrine\ORM\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'], + 'Doctrine\ORM\PersistentCollection' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'], - 'DOMException' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'), - 'DOMStringList' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'), - 'DOMNameList' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'), - 'DOMImplementation' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castImplementation'), - 'DOMImplementationList' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'), - 'DOMNode' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castNode'), - 'DOMNameSpaceNode' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castNameSpaceNode'), - 'DOMDocument' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocument'), - 'DOMNodeList' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'), - 'DOMNamedNodeMap' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'), - 'DOMCharacterData' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castCharacterData'), - 'DOMAttr' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castAttr'), - 'DOMElement' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castElement'), - 'DOMText' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castText'), - 'DOMTypeinfo' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castTypeinfo'), - 'DOMDomError' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castDomError'), - 'DOMLocator' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLocator'), - 'DOMDocumentType' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocumentType'), - 'DOMNotation' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castNotation'), - 'DOMEntity' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castEntity'), - 'DOMProcessingInstruction' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castProcessingInstruction'), - 'DOMXPath' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castXPath'), + 'DOMException' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'], + 'DOMStringList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], + 'DOMNameList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], + 'DOMImplementation' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castImplementation'], + 'DOMImplementationList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], + 'DOMNode' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNode'], + 'DOMNameSpaceNode' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNameSpaceNode'], + 'DOMDocument' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocument'], + 'DOMNodeList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], + 'DOMNamedNodeMap' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], + 'DOMCharacterData' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castCharacterData'], + 'DOMAttr' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castAttr'], + 'DOMElement' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castElement'], + 'DOMText' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castText'], + 'DOMTypeinfo' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castTypeinfo'], + 'DOMDomError' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDomError'], + 'DOMLocator' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLocator'], + 'DOMDocumentType' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocumentType'], + 'DOMNotation' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNotation'], + 'DOMEntity' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castEntity'], + 'DOMProcessingInstruction' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castProcessingInstruction'], + 'DOMXPath' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castXPath'], - 'XmlReader' => array('Symfony\Component\VarDumper\Caster\XmlReaderCaster', 'castXmlReader'), + 'XmlReader' => ['Symfony\Component\VarDumper\Caster\XmlReaderCaster', 'castXmlReader'], - 'ErrorException' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castErrorException'), - 'Exception' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castException'), - 'Error' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castError'), - 'Symfony\Component\DependencyInjection\ContainerInterface' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'), - 'Symfony\Component\HttpFoundation\Request' => array('Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'), - 'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'), - 'Symfony\Component\VarDumper\Caster\TraceStub' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'), - 'Symfony\Component\VarDumper\Caster\FrameStub' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'), - 'Symfony\Component\Debug\Exception\SilencedErrorContext' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'), + 'ErrorException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castErrorException'], + 'Exception' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castException'], + 'Error' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castError'], + 'Symfony\Component\DependencyInjection\ContainerInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], + 'Symfony\Component\HttpFoundation\Request' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'], + 'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'], + 'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'], + 'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'], + 'Symfony\Component\Debug\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'], - 'ProxyManager\Proxy\ProxyInterface' => array('Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'), - 'PHPUnit_Framework_MockObject_MockObject' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'), - 'Prophecy\Prophecy\ProphecySubjectInterface' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'), - 'Mockery\MockInterface' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'), + 'ProxyManager\Proxy\ProxyInterface' => ['Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'], + 'PHPUnit_Framework_MockObject_MockObject' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], + 'Prophecy\Prophecy\ProphecySubjectInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], + 'Mockery\MockInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], - 'PDO' => array('Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdo'), - 'PDOStatement' => array('Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdoStatement'), + 'PDO' => ['Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdo'], + 'PDOStatement' => ['Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdoStatement'], - 'AMQPConnection' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castConnection'), - 'AMQPChannel' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castChannel'), - 'AMQPQueue' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castQueue'), - 'AMQPExchange' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castExchange'), - 'AMQPEnvelope' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castEnvelope'), + 'AMQPConnection' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castConnection'], + 'AMQPChannel' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castChannel'], + 'AMQPQueue' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castQueue'], + 'AMQPExchange' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castExchange'], + 'AMQPEnvelope' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castEnvelope'], - 'ArrayObject' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayObject'), - 'ArrayIterator' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayIterator'), - 'SplDoublyLinkedList' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'), - 'SplFileInfo' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'), - 'SplFileObject' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'), - 'SplFixedArray' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castFixedArray'), - 'SplHeap' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'), - 'SplObjectStorage' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'), - 'SplPriorityQueue' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'), - 'OuterIterator' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castOuterIterator'), + 'ArrayObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayObject'], + 'ArrayIterator' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayIterator'], + 'SplDoublyLinkedList' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'], + 'SplFileInfo' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'], + 'SplFileObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'], + 'SplFixedArray' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFixedArray'], + 'SplHeap' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'], + 'SplObjectStorage' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'], + 'SplPriorityQueue' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'], + 'OuterIterator' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castOuterIterator'], - 'Redis' => array('Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'), - 'RedisArray' => array('Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisArray'), - 'RedisCluster' => array('Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisCluster'), + 'Redis' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'], + 'RedisArray' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisArray'], + 'RedisCluster' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisCluster'], - 'DateTimeInterface' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castDateTime'), - 'DateInterval' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castInterval'), - 'DateTimeZone' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'), - 'DatePeriod' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'), + 'DateTimeInterface' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castDateTime'], + 'DateInterval' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castInterval'], + 'DateTimeZone' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'], + 'DatePeriod' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'], - 'GMP' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'), + 'GMP' => ['Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'], - 'MessageFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'), - 'NumberFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'), - 'IntlTimeZone' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlTimeZone'), - 'IntlCalendar' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlCalendar'), - 'IntlDateFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlDateFormatter'), + 'MessageFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'], + 'NumberFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'], + 'IntlTimeZone' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlTimeZone'], + 'IntlCalendar' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlCalendar'], + 'IntlDateFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlDateFormatter'], - 'Memcached' => array('Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'), + 'Memcached' => ['Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'], - ':curl' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'), - ':dba' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'), - ':dba persistent' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'), - ':gd' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'), - ':mysql link' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castMysqlLink'), - ':pgsql large object' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'), - ':pgsql link' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'), - ':pgsql link persistent' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'), - ':pgsql result' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'), - ':process' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'), - ':stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'), - ':OpenSSL X.509' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'), - ':persistent stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'), - ':stream-context' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'), - ':xml' => array('Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'), - ); + ':curl' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'], + ':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'], + ':dba persistent' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'], + ':gd' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'], + ':mysql link' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castMysqlLink'], + ':pgsql large object' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'], + ':pgsql link' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'], + ':pgsql link persistent' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'], + ':pgsql result' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'], + ':process' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'], + ':stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'], + ':OpenSSL X.509' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'], + ':persistent stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'], + ':stream-context' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'], + ':xml' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'], + ]; protected $maxItems = 2500; protected $maxString = -1; protected $minDepth = 1; - private $casters = array(); + private $casters = []; private $prevErrorHandler; - private $classInfo = array(); + private $classInfo = []; private $filter = 0; /** @@ -225,7 +225,7 @@ abstract class AbstractCloner implements ClonerInterface */ public function cloneVar($var, $filter = 0) { - $this->prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = array()) { + $this->prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) { if (E_RECOVERABLE_ERROR === $type || E_USER_ERROR === $type) { // Cloner never dies throw new \ErrorException($msg, 0, $type, $file, $line); @@ -282,7 +282,7 @@ abstract class AbstractCloner implements ClonerInterface list($i, $parents, $hasDebugInfo) = $this->classInfo[$class]; } else { $i = 2; - $parents = array(strtolower($class)); + $parents = [strtolower($class)]; $hasDebugInfo = method_exists($class, '__debugInfo'); foreach (class_parents($class) as $p) { @@ -295,7 +295,7 @@ abstract class AbstractCloner implements ClonerInterface } $parents[] = '*'; - $this->classInfo[$class] = array($i, $parents, $hasDebugInfo); + $this->classInfo[$class] = [$i, $parents, $hasDebugInfo]; } $a = Caster::castObject($obj, $class, $hasDebugInfo); @@ -309,7 +309,7 @@ abstract class AbstractCloner implements ClonerInterface } } } catch (\Exception $e) { - $a = array((Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)) + $a; + $a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)] + $a; } return $a; @@ -325,7 +325,7 @@ abstract class AbstractCloner implements ClonerInterface */ protected function castResource(Stub $stub, $isNested) { - $a = array(); + $a = []; $res = $stub->value; $type = $stub->class; @@ -336,7 +336,7 @@ abstract class AbstractCloner implements ClonerInterface } } } catch (\Exception $e) { - $a = array((Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)) + $a; + $a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)] + $a; } return $a; diff --git a/src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php b/src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php index 74c1bc8b4c..dc77d03ecd 100644 --- a/src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php +++ b/src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php @@ -39,10 +39,10 @@ class CliDescriptor implements DumpDescriptorInterface public function describe(OutputInterface $output, Data $data, array $context, int $clientId): void { - $io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput(array()), $output); + $io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput([]), $output); $this->dumper->setColors($output->isDecorated()); - $rows = array(array('date', date('r', $context['timestamp']))); + $rows = [['date', date('r', $context['timestamp'])]]; $lastIdentifier = $this->lastIdentifier; $this->lastIdentifier = $clientId; @@ -52,7 +52,7 @@ class CliDescriptor implements DumpDescriptorInterface $this->lastIdentifier = $request['identifier']; $section = sprintf('%s %s', $request['method'], $request['uri']); if ($controller = $request['controller']) { - $rows[] = array('controller', rtrim($this->dumper->dump($controller, true), "\n")); + $rows[] = ['controller', rtrim($this->dumper->dump($controller, true), "\n")]; } } elseif (isset($context['cli'])) { $this->lastIdentifier = $context['cli']['identifier']; @@ -70,15 +70,15 @@ class CliDescriptor implements DumpDescriptorInterface if ($this->supportsHref && $fileLink) { $sourceInfo = sprintf('%s', $fileLink, $sourceInfo); } - $rows[] = array('source', $sourceInfo); + $rows[] = ['source', $sourceInfo]; $file = $source['file_relative'] ?? $source['file']; - $rows[] = array('file', $file); + $rows[] = ['file', $file]; } - $io->table(array(), $rows); + $io->table([], $rows); if (!$this->supportsHref && isset($fileLink)) { - $io->writeln(array('Open source in your IDE/browser:', $fileLink)); + $io->writeln(['Open source in your IDE/browser:', $fileLink]); $io->newLine(); } diff --git a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php index 418f044818..3fb7ac619e 100644 --- a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php @@ -55,9 +55,9 @@ class CliDumper extends AbstractDumper protected $collapseNextHash = false; protected $expandNextHash = false; - private $displayOptions = array( + private $displayOptions = [ 'fileLinkFormat' => null, - ); + ]; private $handlesHrefGracefully; @@ -632,7 +632,7 @@ class CliDumper extends AbstractDumper private function getSourceLink($file, $line) { if ($fmt = $this->displayOptions['fileLinkFormat']) { - return \is_string($fmt) ? strtr($fmt, array('%f' => $file, '%l' => $line)) : $fmt->format($file, $line); + return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line); } return false; diff --git a/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php b/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php index 473bd63dac..fef5dcd127 100644 --- a/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php @@ -49,21 +49,21 @@ class CliDescriptorTest extends TestCase return $s; })); - $descriptor->describe($output, new Data(array(array(123))), $context + array('timestamp' => 1544804268.3668), 1); + $descriptor->describe($output, new Data([[123]]), $context + ['timestamp' => 1544804268.3668], 1); $this->assertStringMatchesFormat(trim($expectedOutput), str_replace(PHP_EOL, "\n", trim($output->fetch()))); } public function provideContext() { - yield 'source' => array( - array( - 'source' => array( + yield 'source' => [ + [ + 'source' => [ 'name' => 'CliDescriptorTest.php', 'line' => 30, 'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php', - ), - ), + ], + ], << array( - array( - 'source' => array( + yield 'source full' => [ + [ + 'source' => [ 'name' => 'CliDescriptorTest.php', 'line' => 30, 'file_relative' => 'src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php', 'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php', 'file_link' => 'phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30', - ), - ), + ], + ], method_exists(OutputFormatterStyle::class, 'setHref') ? << array( - array( - 'source' => array( + yield 'source with hyperlink' => [ + [ + 'source' => [ 'name' => 'CliDescriptorTest.php', 'line' => 30, 'file_relative' => 'src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php', 'file_link' => 'phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30', - ), - ), + ], + ], << array( - array( - 'cli' => array( + yield 'cli' => [ + [ + 'cli' => [ 'identifier' => 'd8bece1c', 'command_line' => 'bin/phpunit', - ), - ), + ], + ], << array( - array( - 'request' => array( + yield 'request' => [ + [ + 'request' => [ 'identifier' => 'd8bece1c', - 'controller' => new Data(array(array('FooController.php'))), + 'controller' => new Data([['FooController.php']]), 'method' => 'GET', 'uri' => 'http://localhost/foo', - ), - ), + ], + ], <<marking = null; - $workflow = new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock()); + $workflow = new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock()); $workflow->getMarking($subject); } @@ -40,7 +40,7 @@ class WorkflowTest extends TestCase { $subject = new \stdClass(); $subject->marking = null; - $workflow = new Workflow(new Definition(array(), array()), new MultipleStateMarkingStore()); + $workflow = new Workflow(new Definition([], []), new MultipleStateMarkingStore()); $workflow->getMarking($subject); } @@ -52,8 +52,8 @@ class WorkflowTest extends TestCase public function testGetMarkingWithImpossiblePlace() { $subject = new \stdClass(); - $subject->marking = array('nope' => 1); - $workflow = new Workflow(new Definition(array(), array()), new MultipleStateMarkingStore()); + $subject->marking = ['nope' => 1]; + $workflow = new Workflow(new Definition([], []), new MultipleStateMarkingStore()); $workflow->getMarking($subject); } @@ -69,7 +69,7 @@ class WorkflowTest extends TestCase $this->assertInstanceOf(Marking::class, $marking); $this->assertTrue($marking->has('a')); - $this->assertSame(array('a' => 1), $subject->marking); + $this->assertSame(['a' => 1], $subject->marking); } public function testGetMarkingWithExistingMarking() @@ -77,7 +77,7 @@ class WorkflowTest extends TestCase $definition = $this->createComplexWorkflowDefinition(); $subject = new \stdClass(); $subject->marking = null; - $subject->marking = array('b' => 1, 'c' => 1); + $subject->marking = ['b' => 1, 'c' => 1]; $workflow = new Workflow($definition, new MultipleStateMarkingStore()); $marking = $workflow->getMarking($subject); @@ -107,19 +107,19 @@ class WorkflowTest extends TestCase $this->assertTrue($workflow->can($subject, 't1')); $this->assertFalse($workflow->can($subject, 't2')); - $subject->marking = array('b' => 1); + $subject->marking = ['b' => 1]; $this->assertFalse($workflow->can($subject, 't1')); // In a workflow net, all "from" places should contain a token to enable // the transition. $this->assertFalse($workflow->can($subject, 't2')); - $subject->marking = array('b' => 1, 'c' => 1); + $subject->marking = ['b' => 1, 'c' => 1]; $this->assertFalse($workflow->can($subject, 't1')); $this->assertTrue($workflow->can($subject, 't2')); - $subject->marking = array('f' => 1); + $subject->marking = ['f' => 1]; $this->assertFalse($workflow->can($subject, 't5')); $this->assertTrue($workflow->can($subject, 't6')); @@ -145,7 +145,7 @@ class WorkflowTest extends TestCase $subject = new \stdClass(); $subject->marking = null; - $dispatchedEvents = array(); + $dispatchedEvents = []; $eventDispatcher = new EventDispatcher(); $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name'); @@ -161,7 +161,7 @@ class WorkflowTest extends TestCase $workflow->can($subject, 't3'); - $this->assertSame(array('workflow_name.guard.t3'), $dispatchedEvents); + $this->assertSame(['workflow_name.guard.t3'], $dispatchedEvents); } public function testCanWithSameNameTransition() @@ -175,7 +175,7 @@ class WorkflowTest extends TestCase $this->assertFalse($workflow->can($subject, 'b_to_c')); $this->assertFalse($workflow->can($subject, 'to_a')); - $subject->marking = array('b' => 1); + $subject->marking = ['b' => 1]; $this->assertFalse($workflow->can($subject, 'a_to_bc')); $this->assertTrue($workflow->can($subject, 'b_to_c')); $this->assertTrue($workflow->can($subject, 'to_a')); @@ -205,17 +205,17 @@ class WorkflowTest extends TestCase $this->assertTrue($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty()); $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty()); - $subject->marking = array('b' => 1); + $subject->marking = ['b' => 1]; $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty()); $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty()); - $subject->marking = array('b' => 1, 'c' => 1); + $subject->marking = ['b' => 1, 'c' => 1]; $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty()); $this->assertTrue($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty()); - $subject->marking = array('f' => 1); + $subject->marking = ['f' => 1]; $this->assertFalse($workflow->buildTransitionBlockerList($subject, 't5')->isEmpty()); $this->assertTrue($workflow->buildTransitionBlockerList($subject, 't6')->isEmpty()); @@ -354,10 +354,10 @@ class WorkflowTest extends TestCase public function testApplyWithSameNameTransition2() { $subject = new \stdClass(); - $subject->marking = array('a' => 1, 'b' => 1); + $subject->marking = ['a' => 1, 'b' => 1]; $places = range('a', 'd'); - $transitions = array(); + $transitions = []; $transitions[] = new Transition('t', 'a', 'c'); $transitions[] = new Transition('t', 'b', 'd'); $definition = new Definition($places, $transitions); @@ -374,10 +374,10 @@ class WorkflowTest extends TestCase public function testApplyWithSameNameTransition3() { $subject = new \stdClass(); - $subject->marking = array('a' => 1); + $subject->marking = ['a' => 1]; $places = range('a', 'd'); - $transitions = array(); + $transitions = []; $transitions[] = new Transition('t', 'a', 'b'); $transitions[] = new Transition('t', 'b', 'c'); $transitions[] = new Transition('t', 'c', 'd'); @@ -398,7 +398,7 @@ class WorkflowTest extends TestCase $eventDispatcher = new EventDispatcherMock(); $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name'); - $eventNameExpected = array( + $eventNameExpected = [ 'workflow.entered', 'workflow.workflow_name.entered', 'workflow.guard', @@ -428,7 +428,7 @@ class WorkflowTest extends TestCase 'workflow.workflow_name.guard', 'workflow.workflow_name.guard.t2', 'workflow.workflow_name.announce.t2', - ); + ]; $marking = $workflow->apply($subject, 't1'); @@ -448,14 +448,14 @@ class WorkflowTest extends TestCase $this->assertEquals($name, $event->getWorkflowName()); }; - $eventNames = array( + $eventNames = [ 'workflow.guard', 'workflow.leave', 'workflow.transition', 'workflow.enter', 'workflow.entered', 'workflow.announce', - ); + ]; foreach ($eventNames as $eventName) { $dispatcher->addListener($eventName, $assertWorkflowName); @@ -466,20 +466,20 @@ class WorkflowTest extends TestCase public function testMarkingStateOnApplyWithEventDispatcher() { - $definition = new Definition(range('a', 'f'), array(new Transition('t', range('a', 'c'), range('d', 'f')))); + $definition = new Definition(range('a', 'f'), [new Transition('t', range('a', 'c'), range('d', 'f'))]); $subject = new \stdClass(); - $subject->marking = array('a' => 1, 'b' => 1, 'c' => 1); + $subject->marking = ['a' => 1, 'b' => 1, 'c' => 1]; $dispatcher = new EventDispatcher(); $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, 'test'); $assertInitialState = function (Event $event) { - $this->assertEquals(new Marking(array('a' => 1, 'b' => 1, 'c' => 1)), $event->getMarking()); + $this->assertEquals(new Marking(['a' => 1, 'b' => 1, 'c' => 1]), $event->getMarking()); }; $assertTransitionState = function (Event $event) { - $this->assertEquals(new Marking(array()), $event->getMarking()); + $this->assertEquals(new Marking([]), $event->getMarking()); }; $dispatcher->addListener('workflow.leave', $assertInitialState); @@ -512,13 +512,13 @@ class WorkflowTest extends TestCase $this->assertEmpty($workflow->getEnabledTransitions($subject)); - $subject->marking = array('d' => 1); + $subject->marking = ['d' => 1]; $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(2, $transitions); $this->assertSame('t3', $transitions[0]->getName()); $this->assertSame('t4', $transitions[1]->getName()); - $subject->marking = array('c' => 1, 'e' => 1); + $subject->marking = ['c' => 1, 'e' => 1]; $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(1, $transitions); $this->assertSame('t5', $transitions[0]->getName()); @@ -535,7 +535,7 @@ class WorkflowTest extends TestCase $this->assertCount(1, $transitions); $this->assertSame('a_to_bc', $transitions[0]->getName()); - $subject->marking = array('b' => 1, 'c' => 1); + $subject->marking = ['b' => 1, 'c' => 1]; $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(3, $transitions); $this->assertSame('b_to_c', $transitions[0]->getName()); @@ -546,7 +546,7 @@ class WorkflowTest extends TestCase class EventDispatcherMock implements \Symfony\Component\EventDispatcher\EventDispatcherInterface { - public $dispatchedEvents = array(); + public $dispatchedEvents = []; public function dispatch($eventName, \Symfony\Component\EventDispatcher\Event $event = null) {