diff --git a/Component/TicketFeatures.php b/Component/TicketFeatures.php index 85597582..3ae72f4d 100644 --- a/Component/TicketFeatures.php +++ b/Component/TicketFeatures.php @@ -18,10 +18,14 @@ */ class TicketFeatures { - private $features; + /** + * @var array + */ + private $features = []; /** - * @param string $messageClass TicketMessage class + * @param array $features + * @param string $messageClass TicketMessage class */ public function __construct(array $features, $messageClass) { @@ -34,18 +38,31 @@ public function __construct(array $features, $messageClass) } /** + * NEXT_MAJOR: Remove the BC checks and return only boolean values. + * * Check if feature exists or whether enabled. * - * @param $feature + * @param string $feature * * @return bool|null */ public function hasFeature($feature) { + $args = \func_get_args(); + if (isset($args[1]) && 'return_strict_bool' === $args[1]) { + return isset($this->features[$feature]) && $this->features[$feature]; + } + if (!isset($this->features[$feature])) { + @trigger_error(sprintf( + 'Returning other type than boolean from "%s()" is deprecated since hackzilla/ticket-bundle 3.x' + .' and will be not allowed in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return null; } - return $this->features[$feature]; + return (bool) $this->features[$feature]; } } diff --git a/Form/Type/TicketMessageType.php b/Form/Type/TicketMessageType.php index 3b4d6466..7a2901db 100644 --- a/Form/Type/TicketMessageType.php +++ b/Form/Type/TicketMessageType.php @@ -59,7 +59,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) ] ); - if ($this->features->hasFeature('attachment')) { + // NEXT_MAJOR: Remove the argument 2 for `TicketFeatures::hasFeature()` + if ($this->features->hasFeature('attachment', 'return_strict_bool')) { $builder ->add( 'attachmentFile', diff --git a/Tests/Component/TicketFeaturesTest.php b/Tests/Component/TicketFeaturesTest.php index 1aa3e5df..40df5c37 100644 --- a/Tests/Component/TicketFeaturesTest.php +++ b/Tests/Component/TicketFeaturesTest.php @@ -21,20 +21,17 @@ final class TicketFeaturesTest extends WebTestCase /** * @dataProvider constructProvider * - * @param array $features * @param string $class */ - public function testConstruct($features, $class) + public function testConstruct(array $features, $class) { - $obj = new TicketFeatures($features, $class); - - $this->assertInstanceOf(TicketFeatures::class, $obj); + $this->assertInstanceOf(TicketFeatures::class, new TicketFeatures($features, $class)); } public function constructProvider() { return [ - [[], '\stdClass'], + [[], \stdClass::class], ]; } @@ -49,13 +46,14 @@ public function testFeatureAttachment(array $features, $class, $compare) $obj = new TicketFeatures($features, $class); $this->assertInstanceOf(TicketFeatures::class, $obj); - $this->assertSame($obj->hasFeature('attachment'), $compare); + // NEXT_MAJOR: Remove the argument 2 for `TicketFeatures::hasFeature()` + $this->assertSame($obj->hasFeature('attachment', 'return_strict_bool'), $compare); } public function featureAttachmentProvider() { return [ - [[], TicketMessage::class, null], + [[], TicketMessage::class, false], [['attachment' => true], TicketMessage::class, false], [['attachment' => true], TicketMessageWithAttachment::class, true], ]; diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index d1007f4e..46e9ad1b 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -1,3 +1,11 @@ +UPGRADE FROM 3.5 to 3.6 +======================= + +## `Hackzilla\Bundle\TicketBundle\Component\TicketFeatures` + +Returning other type than boolean from `TicketFeatures::hasFeature()` is deprecated +and will be not allowed in version 4.0. + UPGRADE FROM 3.4 to 3.5 =======================