[!!!][TASK] Harden \TYPO3\CMS\Extbase\Error\Message 97/59597/5
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Thu, 31 Jan 2019 19:04:47 +0000 (20:04 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Thu, 14 Mar 2019 07:05:39 +0000 (08:05 +0100)
- Use strict type mode
- Use type hints whereever possible

Releases: master
Resolves: #87602
Change-Id: Ieb9d9baa84aca6ab93a3468694ef5886bc7ed119
Reviewed-on: https://review.typo3.org/c/59597
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Breaking-87594-HardenExtbase.rst
typo3/sysext/extbase/Classes/Error/Message.php
typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/NumberValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/RegularExpressionValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/TextValidatorTest.php

index e2558f9..6d55f81 100644 (file)
@@ -38,6 +38,12 @@ While hardening Extbase classes, method signatures changed due to an enforced st
 - :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::getSourceChildPropertiesToBeConverted()`
 - :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::getTypeOfChildProperty()`
 - :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::convertFrom()`
+- :php:`\TYPO3\CMS\Extbase\Error\Message::__construct`
+- :php:`\TYPO3\CMS\Extbase\Error\Message::getMessage`
+- :php:`\TYPO3\CMS\Extbase\Error\Message::getCode`
+- :php:`\TYPO3\CMS\Extbase\Error\Message::getArguments`
+- :php:`\TYPO3\CMS\Extbase\Error\Message::getTitle`
+- :php:`\TYPO3\CMS\Extbase\Error\Message::render`
 
 
 Impact
index 1427971..bfd1d1d 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Error;
 
 /*
@@ -29,7 +31,7 @@ class Message
     /**
      * The error code
      *
-     * @var string
+     * @var int
      */
     protected $code;
 
@@ -55,7 +57,7 @@ class Message
      * @param array $arguments Array of arguments to be replaced in message
      * @param string $title optional title for the message
      */
-    public function __construct($message, $code, array $arguments = [], $title = '')
+    public function __construct(string $message, int $code, array $arguments = [], string $title = '')
     {
         $this->message = $message;
         $this->code = $code;
@@ -68,7 +70,7 @@ class Message
      *
      * @return string The error message
      */
-    public function getMessage()
+    public function getMessage(): string
     {
         return $this->message;
     }
@@ -76,9 +78,9 @@ class Message
     /**
      * Returns the error code
      *
-     * @return string The error code
+     * @return int The error code
      */
-    public function getCode()
+    public function getCode(): int
     {
         return $this->code;
     }
@@ -88,7 +90,7 @@ class Message
      *
      * @return array
      */
-    public function getArguments()
+    public function getArguments(): array
     {
         return $this->arguments;
     }
@@ -98,7 +100,7 @@ class Message
      *
      * @return string
      */
-    public function getTitle()
+    public function getTitle(): string
     {
         return $this->title;
     }
@@ -108,7 +110,7 @@ class Message
      *
      * @return string
      */
-    public function render()
+    public function render(): string
     {
         if (!empty($this->arguments)) {
             return vsprintf($this->message, $this->arguments);
index 5104cc2..f5b2c2e 100644 (file)
@@ -119,7 +119,7 @@ abstract class AbstractValidator implements ValidatorInterface
      */
     protected function addError($message, $code, array $arguments = [], $title = '')
     {
-        $this->result->addError(new \TYPO3\CMS\Extbase\Validation\Error($message, $code, $arguments, $title));
+        $this->result->addError(new \TYPO3\CMS\Extbase\Validation\Error((string)$message, (int)$code, $arguments, (string)$title));
     }
 
     /**
index 1c842cf..6ddbdc1 100644 (file)
@@ -53,7 +53,7 @@ class NumberValidatorTest extends UnitTestCase
     {
         $expectedResult = new \TYPO3\CMS\Extbase\Error\Result();
         // we only test for the error code, after the message translation method is mocked
-        $expectedResult->addError(new \TYPO3\CMS\Extbase\Validation\Error(null, 1221563685));
+        $expectedResult->addError(new \TYPO3\CMS\Extbase\Validation\Error('', 1221563685));
         $this->assertEquals($expectedResult, $this->validator->validate('not a number'));
     }
 }
index 5174d39..7318c2c 100644 (file)
@@ -52,6 +52,6 @@ class RegularExpressionValidatorTest extends UnitTestCase
             ->getMock();
         $errors = $validator->validate('some subject that will not match')->getErrors();
         // we only test for the error code, after the translation Method for message is mocked anyway
-        $this->assertEquals([new \TYPO3\CMS\Extbase\Validation\Error(null, 1221565130)], $errors);
+        $this->assertEquals([new \TYPO3\CMS\Extbase\Validation\Error('', 1221565130)], $errors);
     }
 }
index 69b0530..9735d19 100644 (file)
@@ -71,7 +71,7 @@ class TextValidatorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities()
     {
         // we only test for the error code, after the translation Method for message is mocked anyway
-        $expected = [new \TYPO3\CMS\Extbase\Validation\Error(null, 1221565786)];
+        $expected = [new \TYPO3\CMS\Extbase\Validation\Error('', 1221565786)];
         $this->assertEquals($expected, $this->validator->validate('<span style="color: #BBBBBB;">a nice text</span>')->getErrors());
     }
 }