Repository: pheature-flags/pheature-flags (php)

Issue:
[Toggle Model] Rename current Segment to something as ExactMatchingSegment 
**Epic:** https://github.com/pheature-flags/pheature-flags/issues/2 Toggle Model
**Package:** https://github.com/pheature-flags/toggle-model 

**Description:**

We want to create different types of segments, in the current implementation, we already got one type, Segment. We want to rename it something more explicit like ExactMatchingSegment. This way we will have the ability to create different Segment types maintaining the same naming convention, for example, InCollectionMatchingSegment.

\* *the naming convention is not already defined, we are open for suggestions;-D*

Pull request description:
[#117] Rename current Segment to StrictMatchingSegment
It closes #117  

Patch:
diff --git a/packages/dbal-toggle/src/Read/DbalFeatureFactory.php b/packages/dbal-toggle/src/Read/DbalFeatureFactory.php
index f176efc..469796f 100644
--- a/packages/dbal-toggle/src/Read/DbalFeatureFactory.php
+++ b/packages/dbal-toggle/src/Read/DbalFeatureFactory.php
@@ -10,7 +10,7 @@ use Pheature\Core\Toggle\Read\ToggleStrategies;
 use Pheature\Core\Toggle\Read\ToggleStrategy;
 use Pheature\Model\Toggle\EnableByMatchingSegment;
 use Pheature\Model\Toggle\Feature;
-use Pheature\Model\Toggle\Segment;
+use Pheature\Model\Toggle\StrictMatchingSegment;
 
 final class DbalFeatureFactory
 {
@@ -46,12 +46,12 @@ final class DbalFeatureFactory
             new Segments(
                 ...array_map(
                 /** @param array<string, mixed> $segment */
-                    static function (array $segment): Segment {
+                    static function (array $segment): StrictMatchingSegment {
                         /** @var string $id */
                         $id = $segment['id'];
                         /** @var array<string, mixed> $criteria */
                         $criteria = $segment['criteria'];
-                        return new Segment($id, $criteria);
+                        return new StrictMatchingSegment($id, $criteria);
                     },
                     $segments
                 )
diff --git a/packages/inmemory-toggle/src/InMemoryFeatureFactory.php b/packages/inmemory-toggle/src/InMemoryFeatureFactory.php
index 4b171b9..43304dd 100644
--- a/packages/inmemory-toggle/src/InMemoryFeatureFactory.php
+++ b/packages/inmemory-toggle/src/InMemoryFeatureFactory.php
@@ -10,7 +10,7 @@ use Pheature\Core\Toggle\Read\ToggleStrategies;
 use Pheature\Core\Toggle\Read\ToggleStrategy;
 use Pheature\Model\Toggle\EnableByMatchingSegment;
 use Pheature\Model\Toggle\Feature;
-use Pheature\Model\Toggle\Segment;
+use Pheature\Model\Toggle\StrictMatchingSegment;
 
 final class InMemoryFeatureFactory
 {
@@ -46,12 +46,12 @@ final class InMemoryFeatureFactory
             new Segments(
                 ...array_map(
                     /** @param array<string, mixed> $segment */
-                    static function (array $segment): Segment {
+                    static function (array $segment): StrictMatchingSegment {
                         /** @var string $id */
                         $id = $segment['id'];
                         /** @var array<string, mixed> $criteria */
                         $criteria = $segment['criteria'];
-                        return new Segment($id, $criteria);
+                        return new StrictMatchingSegment($id, $criteria);
                     },
                     $segments
                 )
diff --git a/packages/toggle-model/src/SegmentFactory.php b/packages/toggle-model/src/SegmentFactory.php
index 5c8138c..072d406 100644
--- a/packages/toggle-model/src/SegmentFactory.php
+++ b/packages/toggle-model/src/SegmentFactory.php
@@ -12,8 +12,8 @@ final class SegmentFactory implements ISegmentFactory
 {
     public function create(string $segmentId, string $segmentType, array $payload): ISegment
     {
-        if (Segment::NAME === $segmentType) {
-            return new Segment($segmentId, $payload);
+        if (StrictMatchingSegment::NAME === $segmentType) {
+            return new StrictMatchingSegment($segmentId, $payload);
         }
         if (IdentitySegment::NAME === $segmentType) {
             return new IdentitySegment($segmentId, $payload);
@@ -25,7 +25,7 @@ final class SegmentFactory implements ISegmentFactory
     public function types(): array
     {
         return [
-            Segment::NAME,
+            StrictMatchingSegment::NAME,
             IdentitySegment::NAME,
         ];
     }
diff --git a/packages/toggle-model/src/Segment.php b/packages/toggle-model/src/StrictMatchingSegment.php
similarity index 90%
rename from packages/toggle-model/src/Segment.php
rename to packages/toggle-model/src/StrictMatchingSegment.php
index 4bd1924..8fe760f 100644
--- a/packages/toggle-model/src/Segment.php
+++ b/packages/toggle-model/src/StrictMatchingSegment.php
@@ -6,9 +6,9 @@ namespace Pheature\Model\Toggle;
 
 use Pheature\Core\Toggle\Read\Segment as ISegment;
 
-final class Segment implements ISegment
+final class StrictMatchingSegment implements ISegment
 {
-    public const NAME = 'exact_matching_segment';
+    public const NAME = 'strict_matching_segment';
     private string $id;
     /**
      * @var array<string, mixed>
@@ -45,8 +45,8 @@ final class Segment implements ISegment
         $match = false;
 
         /**
- * @var mixed $value
-*/
+         * @var mixed $value
+         */
         foreach ($this->criteria as $key => $value) {
             if (array_key_exists($key, $payload) && $value === $payload[$key]) {
                 $match = true;


Test patch:
diff --git a/packages/toggle-model/test/EnableByMatchingIdentityIdTest.php b/packages/toggle-model/test/EnableByMatchingIdentityIdTest.php
index 421dd43..df10052 100644
--- a/packages/toggle-model/test/EnableByMatchingIdentityIdTest.php
+++ b/packages/toggle-model/test/EnableByMatchingIdentityIdTest.php
@@ -9,7 +9,7 @@ use Pheature\Core\Toggle\Read\Segments;
 use Pheature\Model\Toggle\EnableByMatchingIdentityId;
 use Pheature\Model\Toggle\Identity;
 use Pheature\Model\Toggle\IdentitySegment;
-use Pheature\Model\Toggle\Segment;
+use Pheature\Model\Toggle\StrictMatchingSegment;
 use PHPUnit\Framework\TestCase;
 
 final class EnableByMatchingIdentityIdTest extends TestCase
@@ -18,7 +18,7 @@ final class EnableByMatchingIdentityIdTest extends TestCase
     {
         $this->expectException(InvalidArgumentException::class);
 
-        $segments = new Segments(new Segment('some_segments', []));
+        $segments = new Segments(new StrictMatchingSegment('some_segments', []));
         new EnableByMatchingIdentityId($segments);
     }
 
diff --git a/packages/toggle-model/test/EnableByMatchingSegmentTest.php b/packages/toggle-model/test/EnableByMatchingSegmentTest.php
index e988409..f0c15e7 100644
--- a/packages/toggle-model/test/EnableByMatchingSegmentTest.php
+++ b/packages/toggle-model/test/EnableByMatchingSegmentTest.php
@@ -7,7 +7,7 @@ namespace Pheature\Test\Model\Toggle;
 use Pheature\Core\Toggle\Read\Segments;
 use Pheature\Model\Toggle\EnableByMatchingSegment;
 use Pheature\Model\Toggle\Identity;
-use Pheature\Model\Toggle\Segment;
+use Pheature\Model\Toggle\StrictMatchingSegment;
 use PHPUnit\Framework\TestCase;
 
 final class EnableByMatchingSegmentTest extends TestCase
@@ -15,7 +15,7 @@ final class EnableByMatchingSegmentTest extends TestCase
     /** @dataProvider getSegmentsCriteria */
     public function testItShouldBeSatisfiedByMatchingSegment(array $criteria): void
     {
-        $segments = new Segments(new Segment('users_from_barcelona', $criteria));
+        $segments = new Segments(new StrictMatchingSegment('users_from_barcelona', $criteria));
 
         $strategy = new EnableByMatchingSegment($segments);
         self::assertTrue($strategy->isSatisfiedBy(new Identity('some_id', $criteria)));
@@ -23,7 +23,7 @@ final class EnableByMatchingSegmentTest extends TestCase
 
     public function testItShouldNotBeSatisfiedByUnMatchingSegment(): void
     {
-        $segments = new Segments(new Segment('users_from_barcelona', [
+        $segments = new Segments(new StrictMatchingSegment('users_from_barcelona', [
             'location' => 'barcelona',
         ]));
 
@@ -45,7 +45,7 @@ final class EnableByMatchingSegmentTest extends TestCase
 
     public function testItShouldNotBeSatisfiedWithoutAnyCriteria(): void
     {
-        $segments = new Segments(new Segment('users_from_barcelona', []));
+        $segments = new Segments(new StrictMatchingSegment('users_from_barcelona', []));
 
         $strategy = new EnableByMatchingSegment($segments);
         self::assertFalse($strategy->isSatisfiedBy(new Identity('some_id', [
@@ -55,7 +55,7 @@ final class EnableByMatchingSegmentTest extends TestCase
 
     public function testItShouldBeSerializedAsArray(): void
     {
-        $segments = new Segments(new Segment('users_from_barcelona', [
+        $segments = new Segments(new StrictMatchingSegment('users_from_barcelona', [
             'location' => 'barcelona',
         ]));
 
diff --git a/packages/toggle-model/test/SegmentFactoryTest.php b/packages/toggle-model/test/SegmentFactoryTest.php
index e78194b..096a417 100644
--- a/packages/toggle-model/test/SegmentFactoryTest.php
+++ b/packages/toggle-model/test/SegmentFactoryTest.php
@@ -6,15 +6,14 @@ namespace Pheature\Test\Model\Toggle;
 
 use Pheature\Core\Toggle\Exception\InvalidSegmentTypeGiven;
 use Pheature\Model\Toggle\IdentitySegment;
-use Pheature\Model\Toggle\Segment;
+use Pheature\Model\Toggle\StrictMatchingSegment;
 use Pheature\Model\Toggle\SegmentFactory;
 use PHPUnit\Framework\TestCase;
 
 final class SegmentFactoryTest extends TestCase
 {
-
     private const SEGMENT_ID = 'some_segment';
-    private const EXACT_MATCHING_SEGMENT = 'exact_matching_segment';
+    private const STRICT_MATCHING_SEGMENT = 'strict_matching_segment';
     private const IDENTITY_SEGMENT = 'identity_segment';
     private const CRITERIA = [
         'some' => 'criteria',
@@ -28,7 +27,7 @@ final class SegmentFactoryTest extends TestCase
         $factory = new SegmentFactory();
 
         self::assertSame([
-            self::EXACT_MATCHING_SEGMENT,
+            self::STRICT_MATCHING_SEGMENT,
             self::IDENTITY_SEGMENT,
         ], $factory->types());
     }
@@ -41,12 +40,12 @@ final class SegmentFactoryTest extends TestCase
         $factory->create(self::SEGMENT_ID, 'unknown_strategy_type', self::CRITERIA);
     }
 
-    public function testItShouldCreateInstancesOfSegment(): void
+    public function testItShouldCreateInstancesOfStrictMatchingSegment(): void
     {
         $factory = new SegmentFactory();
 
-        $segment = $factory->create(self::SEGMENT_ID, self::EXACT_MATCHING_SEGMENT, self::CRITERIA);
-        self::assertInstanceOf(Segment::class, $segment);
+        $segment = $factory->create(self::SEGMENT_ID, self::STRICT_MATCHING_SEGMENT, self::CRITERIA);
+        self::assertInstanceOf(StrictMatchingSegment::class, $segment);
     }
 
     public function testItShouldCreateInstancesOfIdentitySegment(): void
@@ -56,6 +55,4 @@ final class SegmentFactoryTest extends TestCase
         $segment = $factory->create(self::SEGMENT_ID, self::IDENTITY_SEGMENT, self::CRITERIA);
         self::assertInstanceOf(IdentitySegment::class, $segment);
     }
-
 }
-    
\ No newline at end of file