minor #25898 [minor] SCA: reduce repetitive method calls (sequential and in loop) (kalessil)

This PR was merged into the 2.7 branch.

Discussion
----------

[minor] SCA: reduce repetitive method calls (sequential and in loop)

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

609372252f SCA: get rid of repetitive calls
This commit is contained in:
Fabien Potencier 2018-01-23 20:05:41 +01:00
commit 1b92f0685d
6 changed files with 18 additions and 12 deletions

View File

@ -35,10 +35,11 @@ class Application extends BaseApplication
parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : '')); parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : ''));
$this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.')); $inputDefinition = $this->getDefinition();
$this->getDefinition()->addOption(new InputOption('--process-isolation', null, InputOption::VALUE_NONE, 'Launch commands from shell as a separate process.')); $inputDefinition->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.'));
$this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment())); $inputDefinition->addOption(new InputOption('--process-isolation', null, InputOption::VALUE_NONE, 'Launch commands from shell as a separate process.'));
$this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')); $inputDefinition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment()));
$inputDefinition->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
} }
/** /**

View File

@ -110,9 +110,10 @@ abstract class Descriptor implements DescriptorInterface
protected function renderTable(Table $table, $decorated = false) protected function renderTable(Table $table, $decorated = false)
{ {
if (!$decorated) { if (!$decorated) {
$table->getStyle()->setCellRowFormat('%s'); $tableStyle = $table->getStyle();
$table->getStyle()->setCellRowContentFormat('%s'); $tableStyle->setCellRowFormat('%s');
$table->getStyle()->setCellHeaderFormat('%s'); $tableStyle->setCellRowContentFormat('%s');
$tableStyle->setCellHeaderFormat('%s');
} }
$table->render(); $table->render();

View File

@ -467,8 +467,9 @@ class FrameworkExtension extends Extension
if (1 === count($engines)) { if (1 === count($engines)) {
$container->setAlias('templating', (string) reset($engines)); $container->setAlias('templating', (string) reset($engines));
} else { } else {
$templateEngineDefinition = $container->getDefinition('templating.engine.delegating');
foreach ($engines as $engine) { foreach ($engines as $engine) {
$container->getDefinition('templating.engine.delegating')->addMethodCall('addEngine', array($engine)); $templateEngineDefinition->addMethodCall('addEngine', array($engine));
} }
$container->setAlias('templating', 'templating.engine.delegating'); $container->setAlias('templating', 'templating.engine.delegating');
} }

View File

@ -52,8 +52,9 @@ abstract class HttpCache extends BaseHttpCache
protected function forward(Request $request, $raw = false, Response $entry = null) protected function forward(Request $request, $raw = false, Response $entry = null)
{ {
$this->getKernel()->boot(); $this->getKernel()->boot();
$this->getKernel()->getContainer()->set('cache', $this); $container = $this->getKernel()->getContainer();
$this->getKernel()->getContainer()->set($this->getSurrogate()->getName(), $this->getSurrogate()); $container->set('cache', $this);
$container->set($this->getSurrogate()->getName(), $this->getSurrogate());
return parent::forward($request, $raw, $entry); return parent::forward($request, $raw, $entry);
} }

View File

@ -34,8 +34,9 @@ class AddRequestFormatsListener implements EventSubscriberInterface
*/ */
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(GetResponseEvent $event)
{ {
$request = $event->getRequest();
foreach ($this->formats as $format => $mimeTypes) { foreach ($this->formats as $format => $mimeTypes) {
$event->getRequest()->setFormat($format, $mimeTypes); $request->setFormat($format, $mimeTypes);
} }
} }

View File

@ -197,8 +197,9 @@ class ExecutionContext implements ExecutionContextInterface
{ {
$propertyPath = $this->getPropertyPath($subPath); $propertyPath = $this->getPropertyPath($subPath);
$visitor = $this->globalContext->getVisitor();
foreach ($this->resolveGroups($groups) as $group) { foreach ($this->resolveGroups($groups) as $group) {
$this->globalContext->getVisitor()->validate($value, $group, $propertyPath, $traverse, $deep); $visitor->validate($value, $group, $propertyPath, $traverse, $deep);
} }
} }