Skip to content

Commit

Permalink
minor #14121 CS: Pre incrementation/decrementation should be used if …
Browse files Browse the repository at this point in the history
…possible (gharlan)

This PR was merged into the 2.3 branch.

Discussion
----------

CS: Pre incrementation/decrementation should be used if possible

| 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

Fixes provided by new fixer: PHP-CS-Fixer/PHP-CS-Fixer#1113

If this pr is merged I would change the level of the fixer to `symfony`.

Commits
-------

c5123d6 CS: Pre incrementation/decrementation should be used if possible
  • Loading branch information
fabpot committed May 15, 2015
2 parents ebe78bb + c5123d6 commit 984d82c
Show file tree
Hide file tree
Showing 56 changed files with 92 additions and 92 deletions.
Expand Up @@ -121,7 +121,7 @@ public function testLogUTF8LongString()

$shortString = '';
$longString = '';
for ($i = 1; $i <= DbalLogger::MAX_STRING_LENGTH; $i++) {
for ($i = 1; $i <= DbalLogger::MAX_STRING_LENGTH; ++$i) {
$shortString .= $testStringArray[$i % $testStringCount];
$longString .= $testStringArray[$i % $testStringCount];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Expand Up @@ -141,7 +141,7 @@ public function fileExcerpt($file, $line)
$content = preg_split('#<br />#', $code);

$lines = array();
for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; $i++) {
for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; ++$i) {
$lines[] = '<li'.($i == $line ? ' class="selected"' : '').'><code>'.self::fixCodeMarkup($content[$i - 1]).'</code></li>';
}

Expand Down
Expand Up @@ -143,7 +143,7 @@ protected function validateInput(InputInterface $input)
$optionsCount = 0;
foreach ($options as $option) {
if ($input->getOption($option)) {
$optionsCount++;
++$optionsCount;
}
}

Expand Down
Expand Up @@ -135,7 +135,7 @@ public function fileExcerpt($file, $line)
$content = preg_split('#<br />#', $code);

$lines = array();
for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; $i++) {
for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; ++$i) {
$lines[] = '<li'.($i == $line ? ' class="selected"' : '').'><code>'.self::fixCodeMarkup($content[$i - 1]).'</code></li>';
}

Expand Down
Expand Up @@ -148,7 +148,7 @@ protected function parseTokens($tokens, MessageCatalogue $catalog)
{
$tokenIterator = new \ArrayIterator($tokens);

for ($key = 0; $key < $tokenIterator->count(); $key++) {
for ($key = 0; $key < $tokenIterator->count(); ++$key) {
foreach ($this->sequences as $sequence) {
$message = '';
$tokenIterator->seek($key);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/Command/LintCommand.php
Expand Up @@ -142,7 +142,7 @@ protected function getContext($template, $line, $context = 3)
$result = array();
while ($position < $max) {
$result[$position + 1] = $lines[$position];
$position++;
++$position;
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/ClassLoader/ClassMapGenerator.php
Expand Up @@ -95,7 +95,7 @@ private static function findClasses($path)
$classes = array();

$namespace = '';
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
for ($i = 0, $max = count($tokens); $i < $max; ++$i) {
$token = $tokens[$i];

if (is_string($token)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Loader/FileLoader.php
Expand Up @@ -91,7 +91,7 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
}

$resources = is_array($resource) ? $resource : array($resource);
for ($i = 0; $i < $resourcesCount = count($resources); $i++) {
for ($i = 0; $i < $resourcesCount = count($resources); ++$i) {
if (isset(self::$loading[$resources[$i]])) {
if ($i == $resourcesCount - 1) {
throw new FileLoaderImportCircularReferenceException(array_keys(self::$loading));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -759,7 +759,7 @@ public function renderException($e, $output)
'args' => array(),
));

for ($i = 0, $count = count($trace); $i < $count; $i++) {
for ($i = 0, $count = count($trace); $i < $count; ++$i) {
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
$function = $trace[$i]['function'];
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Helper/DialogHelper.php
Expand Up @@ -131,7 +131,7 @@ public function ask(OutputInterface $output, $question, $default = null, array $
// Backspace Character
if ("\177" === $c) {
if (0 === $numMatches && 0 !== $i) {
$i--;
--$i;
// Move cursor backwards
$output->write("\033[1D");
}
Expand Down Expand Up @@ -184,7 +184,7 @@ public function ask(OutputInterface $output, $question, $default = null, array $
} else {
$output->write($c);
$ret .= $c;
$i++;
++$i;

$numMatches = 0;
$ofs = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Helper/TableHelper.php
Expand Up @@ -334,7 +334,7 @@ private function renderRowSeparator()
}

$markup = $this->crossingChar;
for ($column = 0; $column < $count; $column++) {
for ($column = 0; $column < $count; ++$column) {
$markup .= str_repeat($this->horizontalBorderChar, $this->getColumnWidth($column))
.$this->crossingChar
;
Expand Down Expand Up @@ -366,7 +366,7 @@ private function renderRow(array $row, $cellFormat)
}

$this->renderColumnSeparator();
for ($column = 0, $count = $this->getNumberOfColumns(); $column < $count; $column++) {
for ($column = 0, $count = $this->getNumberOfColumns(); $column < $count; ++$column) {
$this->renderCell($row, $column, $cellFormat);
$this->renderColumnSeparator();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Input/ArgvInput.php
Expand Up @@ -123,7 +123,7 @@ private function parseShortOption($token)
private function parseShortOptionSet($name)
{
$len = strlen($name);
for ($i = 0; $i < $len; $i++) {
for ($i = 0; $i < $len; ++$i) {
if (!$this->definition->hasShortcut($name[$i])) {
throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
}
Expand Down
Expand Up @@ -84,7 +84,7 @@ public function translateNthChild(XPathExpr $xpath, FunctionNode $function, $las

if ($last) {
$expr = 'last() - '.$expr;
$b--;
--$b;
}

if (0 !== $b) {
Expand Down
Expand Up @@ -189,9 +189,9 @@ public function testRecursionInArguments()
public function testTooBigArray()
{
$a = array();
for ($i = 0; $i < 20; $i++) {
for ($j = 0; $j < 50; $j++) {
for ($k = 0; $k < 10; $k++) {
for ($i = 0; $i < 20; ++$i) {
for ($j = 0; $j < 50; ++$j) {
for ($k = 0; $k < 10; ++$k) {
$a[$i][$j][$k] = 'value';
}
}
Expand Down
Expand Up @@ -125,7 +125,7 @@ public function testDispatchForClosure()
{
$invoked = 0;
$listener = function () use (&$invoked) {
$invoked++;
++$invoked;
};
$this->dispatcher->addListener('pre.foo', $listener);
$this->dispatcher->addListener('post.foo', $listener);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -324,7 +324,7 @@ public function makePathRelative($endPath, $startPath)
// Find for which directory the common path stops
$index = 0;
while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
$index++;
++$index;
}

// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Finder/Expression/Glob.php
Expand Up @@ -105,7 +105,7 @@ public function toRegex($strictLeadingDot = true, $strictWildcardSlash = true)
$inCurlies = 0;
$regex = '';
$sizeGlob = strlen($this->pattern);
for ($i = 0; $i < $sizeGlob; $i++) {
for ($i = 0; $i < $sizeGlob; ++$i) {
$car = $this->pattern[$i];
if ($firstByte) {
if ($strictLeadingDot && '.' !== $car) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Finder/Glob.php
Expand Up @@ -51,7 +51,7 @@ public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardS
$inCurlies = 0;
$regex = '';
$sizeGlob = strlen($glob);
for ($i = 0; $i < $sizeGlob; $i++) {
for ($i = 0; $i < $sizeGlob; ++$i) {
$car = $glob[$i];
if ($firstByte) {
if ($strictLeadingDot && '.' !== $car) {
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Finder/Tests/FinderTest.php
Expand Up @@ -464,7 +464,7 @@ public function testCountDirectories()
$i = 0;

foreach ($directory as $dir) {
$i++;
++$i;
}

$this->assertCount($i, $directory);
Expand All @@ -476,7 +476,7 @@ public function testCountFiles()
$i = 0;

foreach ($files as $file) {
$i++;
++$i;
}

$this->assertCount($i, $files);
Expand Down
Expand Up @@ -31,7 +31,7 @@ public function testFilterFilesystemIterators()

$c = 0;
foreach ($i as $item) {
$c++;
++$c;
}

$this->assertEquals(1, $c);
Expand All @@ -40,7 +40,7 @@ public function testFilterFilesystemIterators()

$c = 0;
foreach ($i as $item) {
$c++;
++$c;
}

// This would fail with \FilterIterator but works with Symfony\Component\Finder\Iterator\FilterIterator
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/IpUtils.php
Expand Up @@ -110,7 +110,7 @@ public static function checkIp6($requestIp, $ip)
$bytesAddr = unpack('n*', inet_pton($address));
$bytesTest = unpack('n*', inet_pton($requestIp));

for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; $i++) {
for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; ++$i) {
$left = $netmask - 16 * ($i - 1);
$left = ($left <= 16) ? $left : 16;
$mask = ~(0xffff >> $left) & 0xffff;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/ParameterBag.php
Expand Up @@ -113,7 +113,7 @@ public function get($path, $default = null, $deep = false)

$value = $this->parameters[$root];
$currentKey = null;
for ($i = $pos, $c = strlen($path); $i < $c; $i++) {
for ($i = $pos, $c = strlen($path); $i < $c; ++$i) {
$char = $path[$i];

if ('[' === $char) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1557,7 +1557,7 @@ public function getLanguages()
$lang = $codes[1];
}
} else {
for ($i = 0, $max = count($codes); $i < $max; $i++) {
for ($i = 0, $max = count($codes); $i < $max; ++$i) {
if ($i === 0) {
$lang = strtolower($codes[0]);
} else {
Expand Down
Expand Up @@ -196,7 +196,7 @@ public function testGetIterator()

$i = 0;
foreach ($headerBag as $key => $val) {
$i++;
++$i;
$this->assertEquals(array($headers[$key]), $val);
}

Expand Down
Expand Up @@ -233,7 +233,7 @@ public function testGetIterator()

$i = 0;
foreach ($bag as $key => $val) {
$i++;
++$i;
$this->assertEquals($parameters[$key], $val);
}

Expand Down
Expand Up @@ -177,7 +177,7 @@ public function testGetIterator()
$i = 0;
foreach ($this->bag as $key => $val) {
$this->assertEquals($this->array[$key], $val);
$i++;
++$i;
}

$this->assertEquals(count($this->array), $i);
Expand Down
Expand Up @@ -145,7 +145,7 @@ public function testGetIterator()
$i = 0;
foreach ($this->bag as $key => $val) {
$this->assertEquals(array($flashes[$key]), $val);
$i++;
++$i;
}

$this->assertEquals(count($flashes), $i);
Expand Down
Expand Up @@ -203,7 +203,7 @@ public function testGetIterator()
$i = 0;
foreach ($this->session as $key => $val) {
$this->assertEquals($attributes[$key], $val);
$i++;
++$i;
}

$this->assertEquals(count($attributes), $i);
Expand Down
Expand Up @@ -116,7 +116,7 @@ private function computeDeprecationCount()
$count = 0;
foreach ($this->logger->getLogs() as $log) {
if (isset($log['context']['type']) && ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) {
$count++;
++$count;
}
}

Expand Down
Expand Up @@ -45,7 +45,7 @@ public function add(Response $response)
$this->maxAges[] = $response->getMaxAge();
}

$this->embeddedResponses++;
++$this->embeddedResponses;
}

/**
Expand Down
Expand Up @@ -17,7 +17,7 @@ abstract class AbstractProfilerStorageTest extends \PHPUnit_Framework_TestCase
{
public function testStore()
{
for ($i = 0; $i < 10; $i++) {
for ($i = 0; $i < 10; ++$i) {
$profile = new Profile('token_'.$i);
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar');
Expand Down Expand Up @@ -159,7 +159,7 @@ public function testStoreTime()
$dt = new \DateTime('now');
$start = $dt->getTimestamp();

for ($i = 0; $i < 3; $i++) {
for ($i = 0; $i < 3; ++$i) {
$dt->modify('+1 minute');
$profile = new Profile('time_'.$i);
$profile->setIp('127.0.0.1');
Expand All @@ -181,7 +181,7 @@ public function testStoreTime()

public function testRetrieveByEmptyUrlAndIp()
{
for ($i = 0; $i < 5; $i++) {
for ($i = 0; $i < 5; ++$i) {
$profile = new Profile('token_'.$i);
$profile->setMethod('GET');
$this->getStorage()->write($profile);
Expand All @@ -193,7 +193,7 @@ public function testRetrieveByEmptyUrlAndIp()
public function testRetrieveByMethodAndLimit()
{
foreach (array('POST', 'GET') as $method) {
for ($i = 0; $i < 5; $i++) {
for ($i = 0; $i < 5; ++$i) {
$profile = new Profile('token_'.$i.$method);
$profile->setMethod($method);
$this->getStorage()->write($profile);
Expand Down Expand Up @@ -233,7 +233,7 @@ public function testPurge()

public function testDuplicates()
{
for ($i = 1; $i <= 5; $i++) {
for ($i = 1; $i <= 5; ++$i) {
$profile = new Profile('foo'.$i);
$profile->setIp('127.0.0.1');
$profile->setUrl('http://example.net/');
Expand Down
Expand Up @@ -62,7 +62,7 @@ protected function getStorage()
public function testMultiRowIndexFile()
{
$iteration = 3;
for ($i = 0; $i < $iteration; $i++) {
for ($i = 0; $i < $iteration; ++$i) {
$profile = new Profile('token'.$i);
$profile->setIp('127.0.0.'.$i);
$profile->setUrl('http://foo.bar/'.$i);
Expand All @@ -74,7 +74,7 @@ public function testMultiRowIndexFile()
}

$handle = fopen(self::$tmpDir.'/index.csv', 'r');
for ($i = 0; $i < $iteration; $i++) {
for ($i = 0; $i < $iteration; ++$i) {
$row = fgetcsv($handle);
$this->assertEquals('token'.$i, $row[0]);
$this->assertEquals('127.0.0.'.$i, $row[1]);
Expand Down
Expand Up @@ -100,7 +100,7 @@ public function getDsns()
public function testCleanup()
{
$dt = new \DateTime('-2 day');
for ($i = 0; $i < 3; $i++) {
for ($i = 0; $i < 3; ++$i) {
$dt->modify('-1 day');
$profile = new Profile('time_'.$i);
$profile->setTime($dt->getTimestamp());
Expand Down
Expand Up @@ -490,7 +490,7 @@ public function testGetSymbol()
$r->setAccessible(true);
$expected = $r->getValue('Symfony\Component\Intl\NumberFormatter\NumberFormatter');

for ($i = 0; $i <= 17; $i++) {
for ($i = 0; $i <= 17; ++$i) {
$this->assertSame($expected[1][$i], $decimalFormatter->getSymbol($i));
$this->assertSame($expected[2][$i], $currencyFormatter->getSymbol($i));
}
Expand All @@ -505,7 +505,7 @@ public function testGetTextAttribute()
$r->setAccessible(true);
$expected = $r->getValue('Symfony\Component\Intl\NumberFormatter\NumberFormatter');

for ($i = 0; $i <= 5; $i++) {
for ($i = 0; $i <= 5; ++$i) {
$this->assertSame($expected[1][$i], $decimalFormatter->getTextAttribute($i));
$this->assertSame($expected[2][$i], $currencyFormatter->getTextAttribute($i));
}
Expand Down

0 comments on commit 984d82c

Please sign in to comment.