Browse Source

Update signature of Helper::addClass().

Allowing  the class argument to be null doesn't make practical sense.
ADmad 6 years ago
parent
commit
022c3be209
3 changed files with 3 additions and 21 deletions
  1. 0 5
      psalm-baseline.xml
  2. 3 3
      src/View/Helper.php
  3. 0 13
      tests/TestCase/View/HelperTest.php

+ 0 - 5
psalm-baseline.xml

@@ -1299,11 +1299,6 @@
       <code>getTarget</code>
     </PossiblyNullReference>
   </file>
-  <file src="src/View/Helper.php">
-    <PossiblyNullOperand occurrences="1">
-      <code>$class</code>
-    </PossiblyNullOperand>
-  </file>
   <file src="src/View/Helper/FormHelper.php">
     <ImplementedReturnTypeMismatch occurrences="1">
       <code>string</code>

+ 3 - 3
src/View/Helper.php

@@ -144,11 +144,11 @@ class Helper implements EventListenerInterface
      * Adds the given class to the element options
      *
      * @param array $options Array options/attributes to add a class to
-     * @param string|null $class The class name being added.
-     * @param string $key the key to use for class.
+     * @param string $class The class name being added.
+     * @param string $key the key to use for class. Defaults to `'class'`.
      * @return array Array of options with $key set.
      */
-    public function addClass(array $options = [], ?string $class = null, string $key = 'class'): array
+    public function addClass(array $options, string $class, string $key = 'class'): array
     {
         if (isset($options[$key]) && is_array($options[$key])) {
             $options[$key][] = $class;

+ 0 - 13
tests/TestCase/View/HelperTest.php

@@ -209,17 +209,4 @@ class HelperTest extends TestCase
 
         $this->assertEquals($expected, $helper->addClass($input, 'element3'));
     }
-
-    /**
-     * Test addClass() with adding null class
-     */
-    public function testAddClassNull()
-    {
-        $helper = new TestHelper($this->View);
-
-        $input = [];
-        $expected = ['class' => ''];
-
-        $this->assertEquals($expected, $helper->addClass($input, null));
-    }
 }