Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions Component/TicketFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
*/
class TicketFeatures
{
private $features;
/**
* @var array<string, bool>
*/
private $features = [];

/**
* @param string $messageClass TicketMessage class
* @param array<string, bool> $features
* @param string $messageClass TicketMessage class
*/
public function __construct(array $features, $messageClass)
{
Expand All @@ -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];
}
}
3 changes: 2 additions & 1 deletion Form/Type/TicketMessageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 6 additions & 8 deletions Tests/Component/TicketFeaturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

Expand All @@ -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],
];
Expand Down
8 changes: 8 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -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
=======================

Expand Down