Browse Source

minor #1567 PrintToEchoFixer - add to symfony rule set (gharlan)

This PR was merged into the 2.0-dev branch.

Discussion
----------

PrintToEchoFixer - add to symfony rule set

Commits
-------

3958104 PrintToEchoFixer - add to symfony rule set
Dariusz Ruminski 9 years ago
parent
commit
deac154f3a
3 changed files with 86 additions and 2 deletions
  1. 1 1
      README.rst
  2. 1 0
      Symfony/CS/RuleSet.php
  3. 84 1
      Symfony/CS/Tests/Fixtures/Integration/symfony.test

+ 1 - 1
README.rst

@@ -512,7 +512,7 @@ Choose from the list of available fixers:
                         incrementation/decrementation
                         should be used if possible.
 
-* **print_to_echo**
+* **print_to_echo** [@Symfony]
                         Converts print language
                         construct to echo if possible.
 

+ 1 - 0
Symfony/CS/RuleSet.php

@@ -82,6 +82,7 @@ final class RuleSet implements RuleSetInterface
             'phpdoc_type_to_var' => true,
             'phpdoc_var_without_name' => true,
             'pre_increment' => true,
+            'print_to_echo' => true,
             'remove_leading_slash_use' => true,
             'remove_lines_between_uses' => true,
             'return' => true,

+ 84 - 1
Symfony/CS/Tests/Fixtures/Integration/symfony.test

@@ -1,5 +1,5 @@
 --TEST--
-Tntegration of @Symfony.
+Integration of @Symfony.
 --CONFIG--
 {"@Symfony": true}
 --INPUT--
@@ -74,4 +74,87 @@ class FooBar
 
         return !$value;
     }
+
+    private function printText($text)
+    {
+        print $text;
+    }
+}
+--EXPECT--
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Acme;
+
+/**
+ * Coding standards demonstration.
+ */
+class FooBar
+{
+    const SOME_CONST = 42;
+
+    private $fooBar;
+
+    /**
+     * @param string $dummy Some argument description
+     */
+    public function __construct($dummy)
+    {
+        $this->fooBar = $this->transformText($dummy);
+    }
+
+    /**
+     * @param string $dummy   Some argument description
+     * @param array  $options
+     *
+     * @return string|null Transformed input
+     *
+     * @throws \RuntimeException
+     */
+    private function transformText($dummy, array $options = array())
+    {
+        $mergedOptions = array_merge(
+            array(
+                'some_default' => 'values',
+                'another_default' => 'more values',
+            ),
+            $options
+        );
+
+        if (true === $dummy) {
+            return;
+        }
+
+        if ('string' === $dummy) {
+            if ('values' === $mergedOptions['some_default']) {
+                return substr($dummy, 0, 5);
+            }
+
+            return ucwords($dummy);
+        }
+
+        throw new \RuntimeException(sprintf('Unrecognized dummy option "%s"', $dummy));
+    }
+
+    private function reverseBoolean($value = null, $theSwitch = false)
+    {
+        if (!$theSwitch) {
+            return;
+        }
+
+        return !$value;
+    }
+
+    private function printText($text)
+    {
+        echo $text;
+    }
 }