8000 minor #17282 [2.3] Static Code Analysis for Components (kalessil) · symfony/symfony@f1cce4e · GitHub
[go: up one dir, main page]

Skip to content

Commit f1cce4e

Browse files
committed
minor #17282 [2.3] Static Code Analysis for Components (kalessil)
This PR was squashed before being merged into the 2.3 branch (closes #17282). Discussion ---------- [2.3] Static Code Analysis for Components | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Static Code Analysis with Php Inspections (EA Extended): - several code constructs simplification - decoupling statements from foreach - extra colons/parenthesis removal (code style) - correct string functions usage (micro-optimization) - variable functions usage (php 5 compatible) Commits ------- 81f8181 [2.3] Static Code Analysis for Components
2 parents a02bd4b + 81f8181 commit f1cce4e

File tree

18 files changed

+30
-37
lines changed

18 files changed

+30
-37
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function setServerParameter($key, $value)
136136
*/
137137
public function getServerParameter($key, $default = '')
138138
{
139-
return (isset($this->server[$key])) ? $this->server[$key] : $default;
139+
return isset($this->server[$key]) ? $this->server[$key] : $default;
140140
}
141141

142142
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function setLayout($layout)
111111

112112
default:
113113
throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
114-
};
114+
}
115115

116116
return $this;
117117
}

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function_exists('php_uname') ? php_uname('s') : '',
131131
PHP_OS,
132132
);
133133

134-
return false !== stristr(implode(';', $checks), 'OS400');
134+
return false !== stripos(implode(';', $checks), 'OS400');
135135
}
136136

137137
/**

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,6 @@ public static function camelize($id)
536536
*/
537537
public static function underscore($id)
538538
{
539-
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
539+
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), str_replace('_', '.', $id)));
540540
}
541541
}

src/Symfony/Component/DependencyInjection/Extension/Extension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ public function getConfiguration(array $config, ContainerBuilder $container)
9191
$container->addResource(new FileResource($r->getFileName()));
9292

9393
if (!method_exists($class, '__construct')) {
94-
$configuration = new $class();
95-
96-
return $configuration;
94+
return new $class();
9795
}
9896
}
9997
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ private function parseImports(SimpleXMLElement $xml, $file)
9191
return;
9292
}
9393

94+
$defaultDirectory = dirname($file);
9495
foreach ($imports as $import) {
95-
$this->setCurrentDir(dirname($file));
96+
$this->setCurrentDir($defaultDirectory);
9697
$this->import((string) $import['resource'], null, (bool) $import->getAttributeAsPhp('ignore-errors'), $file);
9798
}
9899
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ private function parseImports($content, $file)
9494
throw new InvalidArgumentException(sprintf('The "imports" key should contain an array in %s. Check your YAML syntax.', $file));
9595
}
9696

97+
$defaultDirectory = dirname($file);
9798
foreach ($content['imports'] as $import) {
9899
if (!is_array($import)) {
99100
throw new InvalidArgumentException(sprintf('The values in the "imports" key should be arrays in %s. Check your YAML syntax.', $file));
100101
}
101102

102-
$this->setCurrentDir(dirname($file));
103+
$this->setCurrentDir($defaultDirectory);
103104
$this->import($import['resource'], null, isset($import['ignore_errors']) ? (bool) $import['ignore_errors'] : false, $file);
104105
}
105106
}

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public function isAbsolutePath($file)
431431
return strspn($file, '/\\', 0, 1)
432432
|| (strlen($file) > 3 && ctype_alpha($file[0])
433433
&& substr($file, 1, 1) === ':'
434-
&& (strspn($file, '/\\', 2, 1))
434+
&& strspn($file, '/\\', 2, 1)
435435
)
436436
|| null !== parse_url($file, PHP_URL_SCHEME)
437437
;

src/Symfony/Component/HttpFoundation/HeaderBag.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function add(array $headers)
113113
*/
114114
public function get($key, $default = null, $first = true)
115115
{
116-
$key = strtr(strtolower($key), '_', '-');
116+
$key = str_replace('_', '-', strtolower($key));
117117

118118
if (!array_key_exists($key, $this->headers)) {
119119
if (null === $default) {
@@ -139,7 +139,7 @@ public function get($key, $default = null, $first = true)
139139
*/
140140
public function set($key, $values, $replace = true)
141141
{
142-
$key = strtr(strtolower($key), '_', '-');
142+
$key = str_replace('_', '-', strtolower($key));
143143

144144
$values = array_values((array) $values);
145145

@@ -163,7 +163,7 @@ public function set($key, $values, $replace = true)
163163
*/
164164
public function has($key)
165165
{
166-
return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
166+
return array_key_exists(str_replace('_', '-', strtolower($key)), $this->headers);
167167
}
168168

169169
/**
@@ -186,7 +186,7 @@ public function contains($key, $value)
186186
*/
187187
public function remove($key)
188188
{
189-
$key = strtr(strtolower($key), '_', '-');
189+
$key = str_replace('_', '-', strtolower($key));
190190

191191
unset($this->headers[$key]);
192192

src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function set($key, $values, $replace = true)
9999
{
100100
parent::set($key, $values, $replace);
101101

102-
$uniqueKey = strtr(strtolower($key), '_', '-');
102+
$uniqueKey = str_replace('_', '-', strtolower($key));
103103
$this->headerNames[$uniqueKey] = $key;
104104

105105
// ensure the cache-control header has sensible defaults
@@ -118,7 +118,7 @@ public function remove($key)
118118
{
119119
parent::remove($key);
120120

121-
$uniqueKey = strtr(strtolower($key), '_', '-');
121+
$uniqueKey = str_replace('_', '-', strtolower($key));
122122
unset($this->headerNames[$uniqueKey]);
123123

124124
if ('cache-control' === $uniqueKey) {

src/Symfony/Component/HttpKernel/Bundle/Bundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function registerCommands(Application $application)
181181
foreach ($finder as $file) {
182182
$ns = $prefix;
183183
if ($relativePath = $file->getRelativePath()) {
184-
$ns .= '\\'.strtr($relativePath, '/', '\\');
184+
$ns .= '\\'.str_replace('/', '\\', $relativePath);
185185
}
186186
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
187187
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {

src/Symfony/Component/HttpKernel/HttpCache/Store.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ class Store implements StoreInterface
3838
public function __construct($root)
3939
{
4040
$this->root = $root;
41-
if (!is_dir($this->root)) {
42-
if (false === @mkdir($this->root, 0777, true) && !is_dir($this->root)) {
43-
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
44-
}
41+
if (!is_dir($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) {
42+
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
4543
}
4644
$this->keyCache = new \SplObjectStorage();
4745
$this->locks = array();
@@ -249,10 +247,8 @@ public function invalidate(Request $request)
249247
}
250248
}
251249

252-
if ($modified) {
253-
if (false === $this->save($key, serialize($entries))) {
254-
throw new \RuntimeException('Unable to store the metadata.');
255-
}
250+
if ($modified && false === $this->save($key, serialize($entries))) {
251+
throw new \RuntimeException('Unable to store the metadata.');
256252
}
257253
}
258254

@@ -273,7 +269,7 @@ private function requestsMatch($vary, $env1, $env2)
273269
}
274270

275271
foreach (preg_split('/[\s,]+/', $vary) as $header) {
276-
$key = strtr(strtolower($header), '_', '-');
272+
$key = str_replace('_', '-', strtolower($header));
277273
$v1 = isset($env1[$key]) ? $env1[$key] : null;
278274
$v2 = isset($env2[$key]) ? $env2[$key] : null;
279275
if ($v1 !== $v2) {

src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ protected function fetch($db, $query, array $args = array())
187187
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
188188
}
189189
$stmt->execute();
190-
$return = $stmt->fetchAll(\PDO::FETCH_ASSOC);
191190

192-
return $return;
191+
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
193192
}
194193

195194
protected function close($db)

src/Symfony/Component/HttpKernel/UriSigner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function sign($uri)
5151

5252
$uri = $this->buildUrl($url, $params);
5353

54-
return $uri.(false === (strpos($uri, '?')) ? '?' : '&').'_hash='.$this->computeHash($uri);
54+
return $uri.(false === strpos($uri, '?') ? '?' : '&').'_hash='.$this->computeHash($uri);
5555
}
5656

5757
/**

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ private function writeProperty(&$object, $property, $singular, $value)
442442
}
443443

444444
foreach ($itemToRemove as $item) {
445-
call_user_func(array($object, $access[self::ACCESS_REMOVER]), $item);
445+
$object->{$access[self::ACCESS_REMOVER]}($item);
446446
}
447447

448448
foreach ($itemsToAdd as $item) {
449-
call_user_func(array($object, $access[self::ACCESS_ADDER]), $item);
449+
$object->{$access[self::ACCESS_ADDER]}($item);
450450
}
451451
} elseif (!$access[self::ACCESS_HAS_PROPERTY] && property_exists($object, $property)) {
452452
// Needed to support \stdClass instances. We need to explicitly

src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,8 @@ public function validateAndDecode($entryPointKey, $expectedRealm)
172172
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s" (%s)', $this->header, implode(', ', $keys)));
173173
}
174174

175-
if ('auth' === $this->elements['qop']) {
176-
if (!isset($this->elements['nc']) || !isset($this->elements['cnonce'])) {
177-
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s"', $this->header));
178-
}
175+
if ('auth' === $this->elements['qop'] && !isset($this->elements['nc'], $this->elements['cnonce'])) {
176+
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s"', $this->header));
179177
}
180178

181179
if ($expectedRealm !== $this->elements['realm']) {

src/Symfony/Component/Translation/Dumper/IcuResFileDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public function dump(MessageCatalogue $messages, $options = array())
3030
}
3131

3232
// save a file for each domain
33+
$file = $messages->getLocale().'.'.$this->getExtension();
3334
foreach ($messages->getDomains() as $domain) {
34-
$file = $messages->getLocale().'.'.$this->getExtension();
3535
$path = $options['path'].'/'.$domain.'/';
3636

3737
if (!is_dir($path) && !@mkdir($path) && !is_dir($path)) {

src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected function parseFile($path)
190190
*/
191191
private function loadClassMetadataFromXml(ClassMetadata $metadata, $classDescription)
192192
{
193-
foreach ($classDescription->{'group-sequence-provider'} as $_) {
193+
if (count($classDescription->{'group-sequence-provider'}) > 0) {
194194
$metadata->setGroupSequenceProvider(true);
195195
}
196196

0 commit comments

Comments
 (0)
0