8000 [CS] Replace easy occurences of ?: with ?? by fancyweb · Pull Request #40727 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[CS] Replace easy occurences of ?: with ?? #40727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class VarDumperFormatter implements FormatterInterface

public function __construct(VarCloner $cloner = null)
{
$this->cloner = $cloner ?: new VarCloner();
$this->cloner = $cloner ?? new VarCloner();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/DumpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function dump(Environment $env, $context)
}

$dump = fopen('php://memory', 'r+');
$this->dumper = $this->dumper ?: new HtmlDumper();
$this->dumper = $this->dumper ?? new HtmlDumper();
$this->dumper->setCharset($env->getCharset());

foreach ($vars as $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(CacheClearerInterface $cacheClearer, Filesystem $fil
parent::__construct();

$this->cacheClearer = $cacheClearer;
$this->filesystem = $filesystem ?: new Filesystem();
$this->filesystem = $filesystem ?? new Filesystem();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(ContainerInterface $container, $resource, array $opt
{
$this->container = $container;
$this->resource = $resource;
$this->context = $context ?: new RequestContext();
$this->context = $context ?? new RequestContext();
$this->logger = $logger;
$this->setOptions($options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WebProfilerExtension extends ProfilerExtension

public function __construct(HtmlDumper $dumper = null)
{
$this->dumper = $dumper ?: new HtmlDumper();
$this->dumper = $dumper ?? new HtmlDumper();
$this->dumper->setOutput($this->output = fopen('php://memory', 'r+'));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Asset/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Package implements PackageInterface
public function __construct(VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
{
$this->versionStrategy = $versionStrategy;
$this->context = $context ?: new NullContext();
$this->context = $context ?? new NullContext();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ abstract class Client
public function __construct(array $server = [], History $history = null, CookieJar $cookieJar = null)
{
$this->setServerParameters($server);
$this->history = $history ?: new History();
$this->cookieJar = $cookieJar ?: new CookieJar();
$this->history = $history ?? new History();
$this->cookieJar = $cookieJar ?? new CookieJar();
}

/**
Expand Down
< 4F6 td id="diff-d28fba5cd3ab50a3419f120b08ecac78ef080e72b556dc335d7680e40c3cabaeL29" data-line-number="29" class="blob-num blob-num-context js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $name = null, string $type = 'array', NodeBui
if (null === $name) {
@trigger_error('A tree builder without a root node is deprecated since Symfony 4.2 and 106D2 will not be supported anymore in 5.0.', \E_USER_DEPRECATED);
} else {
$builder = $builder ?: new NodeBuilder();
$builder = $builder ?? new NodeBuilder();
$this->root = $builder->node($name, $type)->setParent($this);
}
}
Expand All @@ -50,7 +50,7 @@ public function root($name, $type = 'array', NodeBuilder $builder = null)
{
@trigger_error(sprintf('The "%s()" method called for the "%s" configuration is deprecated since Symfony 4.3, pass the root name to the constructor instead.', __METHOD__, $name), \E_USER_DEPRECATED);

$builder = $builder ?: new NodeBuilder();
$builder = $builder ?? new NodeBuilder();

return $this->root = $builder->node($name, $type)->setParent($this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class OutputFormatterStyleStack implements ResetInterface

public function __construct(OutputFormatterStyleInterface $emptyStyle = null)
{
$this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle();
$this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle();
$this->reset();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Output/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class Output implements OutputInterface
public function __construct(?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null)
{
$this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
$this->formatter = $formatter ?: new OutputFormatter();
$this->formatter = $formatter ?? new OutputFormatter();
$this->formatter->setDecorated($decorated);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/CssSelector/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Parser implements ParserInterface

public function __construct(Tokenizer $tokenizer = null)
{
$this->tokenizer = $tokenizer ?: new Tokenizer();
$this->tokenizer = $tokenizer ?? new Tokenizer();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/CssSelector/XPath/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Translator implements TranslatorInterface

public function __construct(ParserInterface $parser = null)
{
$this->mainParser = $parser ?: new Parser();
$this->mainParser = $parser ?? new Parser();

$this
->registerExtension(new Extension\NodeExtension())
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Container implements ResettableContainerInterface

public function __construct(ParameterBagInterface $parameterBag = null)
{
$this->parameterBag = $parameterBag ?: new EnvPlaceholderParameterBag();
$this->parameterBag = $parameterBag ?? new EnvPlaceholderParameterBag();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function getReflectionClass(?string $class, bool $throw = true): ?\Reflec

if ($this->trackResources) {
if (!$classReflector) {
$this->addResource($resource ?: new ClassExistenceResource($class, false));
$this->addResource($resource ?? new ClassExistenceResource($class, false));
} elseif (!$classReflector->isInternal()) {
$path = $classReflector->getFileName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function testCanDecorateServiceLocator()
public function testYamlContainerCompiles($directory, $actualServiceId, $expectedServiceId, ContainerBuilder $mainContainer = null)
{
// allow a container to be passed in, which might have autoconfigure settings
$container = $mainContainer ?: new ContainerBuilder();
$container = $mainContainer ?? new ContainerBuilder();
$container->setResourceTracking(false);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Fixtures/yaml/integration/'.$directory));
$loader->load('main.yml');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ExpressionLanguage
*/
public function __construct(CacheItemPoolInterface $cache = null, array $providers = [])
{
$this->cache = $cache ?: new ArrayAdapter();
$this->cache = $cache ?? new ArrayAdapter();
$this->registerFunctions();
foreach ($providers as $provider) {
$this->registerProvider($provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null,
throw new \TypeError(sprintf('Argument 3 passed to "%s()" must be an instance of "%s", "%s" given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
}
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(new PropertyAccessDecorator(new DefaultChoiceListFactory(), $this->propertyAccessor));
$this->choiceListFactory = $choiceListFactory ?? new CachingFactoryDecorator(new PropertyAccessDecorator(new DefaultChoiceListFactory(), $this->propertyAccessor));
$this->translator = $translator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(string $inputTimezone = null, string $outputTimezone

$this->fields = $fields;
$this->pad = $pad;
$this->referenceDate = $referenceDate ?: new \DateTimeImmutable('1970-01-01 00:00:00');
$this->referenceDate = $referenceDate ?? new \DateTimeImmutable('1970-01-01 00:00:00');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ChoiceType extends AbstractType
*/
public function __construct(ChoiceListFactoryInterface $choiceListFactory = null, $translator = null)
{
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(
$this->choiceListFactory = $choiceListFactory ?? new CachingFactoryDecorator(
new PropertyAccessDecorator(
new DefaultChoiceListFactory()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(string $fieldName, CsrfTokenManagerInterface $tokenM
$this->errorMessage = $errorMessage;
$this->translator = $translator;
$this->translationDomain = $translationDomain;
$this->serverParams = $serverParams ?: new ServerParams();
$this->serverParams = $serverParams ?? new ServerParams();
}

public function preSubmit(FormEvent $event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HttpFoundationRequestHandler implements RequestHandlerInterface

public function __construct(ServerParams $serverParams = null)
{
$this->serverParams = $serverParams ?: new ServerParams();
$this->serverParams = $serverParams ?? new ServerParams();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FormTypeHttpFoundationExtension extends AbstractTypeExtension

public function __construct(RequestHandlerInterface $requestHandler = null)
{
$this->requestHandler = $requestHandler ?: new HttpFoundationRequestHandler();
$this->requestHandler = $requestHandler ?? new HttpFoundationRequestHandler();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormFactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function getFormFactory()
$extensions[] = new PreloadedExtension($this->types, $this->typeExtensions, $typeGuesser);
}

$registry = new FormRegistry($extensions, $this->resolvedTypeFactory ?: new ResolvedFormTypeFactory());
$registry = new FormRegistry($extensions, $this->resolvedTypeFactory ?? new ResolvedFormTypeFactory());

return new FormFactory($registry);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/NativeRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class NativeRequestHandler implements RequestHandlerInterface

public function __construct(ServerParams $params = null)
{
$this->serverParams = $params ?: new ServerParams();
$this->serverParams = $params ?? new ServerParams();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/HttpFoundation/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable

public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
{
$this->storage = $storage ?: new NativeSessionStorage();
$this->storage = $storage ?? new NativeSessionStorage();

$attributes = $attributes ?: new AttributeBag();
$attributes = $attributes ?? new AttributeBag();
$this->attributeName = $attributes->getName();
$this->registerBag($attributes);

$flashes = $flashes ?: new FlashBag();
$flashes = $flashes ?? new FlashBag();
$this->flashName = $flashes->getName();
$this->registerBag($flashes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class ArgumentResolver implements ArgumentResolverInterface

public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, iterable $argumentValueResolvers = [])
{
$this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory();
$this->argumentMetadataFactory = $argumentMetadataFactory ?? new ArgumentMetadataFactory();
$this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
{
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
$this->resolver = $resolver;
$this->requestStack = $requestStack ?: new RequestStack();
$this->requestStack = $requestStack ?? new RequestStack();
$this->argumentResolver = $argumentResolver;

if (null === $this->argumentResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function testDoesNotThrowIfRequestDoesNotHaveASession()
private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, Response $response = null)
{
$request->setSession($this->session);
$response = $response ?: new Response();
$response = $response ?? new Response();
$kernel = $this->createMock(HttpKernelInterface::class);
$event = new ResponseEvent($kernel, $request, $type, $response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class AbstractTransport implements TransportInterface
public function __construct(EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
{
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
$this->logger = $logger ?: new NullLogger();
$this->logger = $logger ?? new NullLogger();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(AbstractStream $stream = null, EventDispatcherInterf
{
parent::__construct($dispatcher, $logger);

$this->stream = $stream ?: new SocketStream();
$this->stream = $stream ?? new SocketStream();
}

public function getStream(): AbstractStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function testReceivesMessages()

private function getTransport(SerializerInterface $serializer = null, Connection $connection = null): AmqpTransport
{
$serializer = $serializer ?: $this->createMock(SerializerInterface::class);
$connection = $connection ?: $this->createMock(Connection::class);
$serializer = $serializer ?? $this->createMock(SerializerInterface::class);
$connection = $connection ?? $this->createMock(Connection::class);

return new AmqpTransport($connection, $serializer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function testReceivesMessages()

private function getTransport(SerializerInterface $serializer = null, Connection $connection = null): DoctrineTransport
{
$serializer = $serializer ?: $this->createMock(SerializerInterface::class);
$connection = $connection ?: $this->createMock(Connection::class);
$serializer = $serializer ?? $this->createMock(SerializerInterface::class);
$connection = $connection ?? $this->createMock(Connection::class);

return new DoctrineTransport($connection, $serializer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function testReceivesMessages()

private function getTransport(SerializerInterface $serializer = null, Connection $connection = null): RedisTransport
{
$serializer = $serializer ?: $this->createMock(SerializerInterface::class);
$connection = $connection ?: $this->createMock(Connection::class);
$serializer = $serializer ?? $this->createMock(SerializerInterface::class);
$connection = $connection ?? $this->createMock(Connection::class);

return new RedisTransport($connection, $serializer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(array $connectionOptions, array $exchangeOptions, ar
], $connectionOptions);
$this->exchangeOptions = $exchangeOptions;
$this->queuesOptions = $queuesOptions;
$this->amqpFactory = $amqpFactory ?: new AmqpFactory();
$this->amqpFactory = $amqpFactory ?? new AmqpFactory();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(array $configuration, array $connectionCredentials =
throw new LogicException('The redis transport requires php-redis 4.3.0 or higher.');
}

$this->connection = $redis ?: new \Redis();
$this->connection = $redis ?? new \Redis();
$this->connection->connect($connectionCredentials['host'] ?? '127.0.0.1', $connectionCredentials['port'] ?? 6379);
$this->connection->setOption(\Redis::OPT_SERIALIZER, $redisOptions['serializer'] ?? \Redis::SERIALIZER_PHP);

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __construct(LoaderInterface $loader, $resource, array $options =
$this->loader = $loader;
$this->resource = $resource;
$this->logger = $logger;
$this->context = $context ?: new RequestContext();
$this->context = $context ?? new RequestContext();
$this->setOptions($options);
$this->defaultLocale = $defaultLocale;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getUrlMatcher(RouteCollection $routes, RequestContext $contex
$compiledRoutes = $dumper->getCompiledRoutes();

return $this->getMockBuilder(TestCompiledRedirectableUrlMatcher::class)
->setConstructorArgs([$compiledRoutes, $context ?: new RequestContext()])
->setConstructorArgs([$compiledRoutes, $context ?? new RequestContext()])
->setMethods(['redirect'])
->getMock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected function getUrlMatcher(RouteCollection $routes, RequestContext $contex
{
$dumper = new CompiledUrlMatcherDumper($routes);

return new CompiledUrlMatcher($dumper->getCompiledRoutes(), $context ?: new RequestContext());
return new CompiledUrlMatcher($dumper->getCompiledRoutes(), $context ?? new RequestContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getUrlMatcher(RouteCollection $routes, RequestContext $contex
eval('?>'.$dumper->dump(['class' => $class, 'base_class' => 'Symfony\Component\Routing\Tests\Matcher\TestDumpedRedirectableUrlMatcher']));

return $this->getMockBuilder($class)
->setConstructorArgs([$context ?: new RequestContext()])
->setConstructorArgs([$context ?? new RequestContext()])
->setMethods(['redirect'])
->getMock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ protected function getUrlMatcher(RouteCollection $routes, RequestContext $contex
$dumper = new PhpMatcherDumper($routes);
eval('?>'.$dumper->dump(['class' => $class]));

return new $class($context ?: new RequestContext());
return new $class($context ?? new RequestContex 741A t());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ public function testTrailingRequirementWithDefault_A()

protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
return $this->getMockForAbstractClass(RedirectableUrlMatcher::class, [$routes, $context ?: new RequestContext()]);
return $this->getMockForAbstractClass(RedirectableUrlMatcher::class, [$routes, $context ?? new RequestContext()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ public function testRoutesWithConditions()

protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
return new TraceableUrlMatcher($routes, $context ?: new RequestContext());
return new TraceableUrlMatcher($routes, $context ?? new RequestContext());
}
}
Loading
0