Skip to content

Commit 78cc93c

Browse files
kalessilfabpot
authored andcommitted
[2.3] Static Code Analysis for Components
1 parent 986e3d1 commit 78cc93c

File tree

17 files changed

+25
-20
lines changed

17 files changed

+25
-20
lines changed

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function __toString()
9393
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
9494

9595
if ($dateTime === false) {
96+
// this throw will provoke PHP fatal
9697
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $this->expires);
9798
}
9899

src/Symfony/Component/Console/Descriptor/ApplicationDescription.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ private function sortCommands(array $commands)
144144
}
145145
ksort($namespacedCommands);
146146

147-
foreach ($namespacedCommands as &$commands) {
148-
ksort($commands);
147+
foreach ($namespacedCommands as &$commandsSet) {
148+
ksort($commandsSet);
149149
}
150+
// unset reference to keep scope clear
151+
unset($commandsSet);
150152

151153
return $namespacedCommands;
152154
}

src/Symfony/Component/Console/Helper/DialogHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function select(OutputInterface $output, $question, $choices, $default =
7171
if (empty($choices[$value])) {
7272
throw new \InvalidArgumentException(sprintf($errorMessage, $value));
7373
}
74-
array_push($multiselectChoices, $value);
74+
$multiselectChoices[] = $value;
7575
}
7676

7777
if ($multiselect) {

src/Symfony/Component/Console/Helper/TableHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function addRow(array $row)
148148
reset($this->rows);
149149

150150
foreach ($row as $key => $cellValue) {
151-
if (!strstr($cellValue, "\n")) {
151+
if (false === strpos($cellValue, "\n")) {
152152
continue;
153153
}
154154

src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function process(ContainerBuilder $container)
3939
$this->compiler = $container->getCompiler();
4040
$this->formatter = $this->compiler->getLoggingFormatter();
4141

42-
foreach (array_keys($container->getDefinitions()) as $id) {
42+
foreach ($container->getDefinitions() as $id => $definition) {
4343
// yes, we are specifically fetching the definition from the
4444
// container to ensure we are not operating on stale data
4545
$definition = $container->getDefinition($id);

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
312312
}
313313

314314
$alternatives = array();
315-
foreach (array_keys($this->services) as $key) {
315+
foreach ($this->services as $key => $associatedService) {
316316
$lev = levenshtein($id, $key);
317317
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
318318
$alternatives[] = $key;

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private function validate($content, $file)
304304
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid. It should contain an array. Check your YAML syntax.', $file));
305305
}
306306

307-
foreach (array_keys($content) as $namespace) {
307+
foreach ($content as $namespace => $data) {
308308
if (in_array($namespace, array('imports', 'parameters', 'services'))) {
309309
continue;
310310
}

src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function get($name)
9898
}
9999

100100
$alternatives = array();
101-
foreach (array_keys($this->parameters) as $key) {
101+
foreach ($this->parameters as $key => $parameterValue) {
102102
$lev = levenshtein($name, $key);
103103
if ($lev <= strlen($name) / 3 || false !== strpos($key, $name)) {
104104
$alternatives[] = $key;

src/Symfony/Component/DomCrawler/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected function canonicalizePath($path)
163163
if ('..' === $segment) {
164164
array_pop($output);
165165
} elseif ('.' !== $segment) {
166-
array_push($output, $segment);
166+
$output[] = $segment;
167167
}
168168
}
169169

src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function hasListeners($eventName = null)
124124
public function getListeners($eventName = null)
125125
{
126126
if (null === $eventName) {
127-
foreach (array_keys($this->listenerIds) as $serviceEventName) {
127+
foreach ($this->listenerIds as $serviceEventName => $args) {
128128
$this->lazyLoad($serviceEventName);
129129
}
130130
} else {

0 commit comments

Comments
 (0)