Code Duplication    Length = 28-28 lines in 2 locations

src/Strategy/DateTimeFormatStrategy.php 1 location

@@ 5-32 (lines=28) @@
2
3
namespace Uvinum\Joiner\Strategy;
4
5
final class DateTimeFormatStrategy implements Strategy
6
{
7
    /** @var Strategy | null */
8
    private $nextStrategy;
9
10
    public function __construct($nextStrategy = null)
11
    {
12
        $this->nextStrategy = $nextStrategy;
13
    }
14
15
    public function execute($object)
16
    {
17
        if ($object instanceof \DateTimeInterface) {
18
            return $object->format('Y-m-d H:i:s');
19
        }
20
21
        return $this->next($object);
22
    }
23
24
    public function next($object)
25
    {
26
        if (null !== $this->nextStrategy) {
27
            return $this->nextStrategy->execute($object);
28
        }
29
30
        return null;
31
    }
32
}
33

src/Strategy/ToStringStrategy.php 1 location

@@ 5-32 (lines=28) @@
2
3
namespace Uvinum\Joiner\Strategy;
4
5
final class ToStringStrategy implements Strategy
6
{
7
    /** @var Strategy | null */
8
    private $nextStrategy;
9
10
    public function __construct($nextStrategy = null)
11
    {
12
        $this->nextStrategy = $nextStrategy;
13
    }
14
15
    public function execute($object)
16
    {
17
        if (\method_exists($object, '__toString')) {
18
            return $object->__toString();
19
        }
20
21
        return $this->next($object);
22
    }
23
24
    public function next($object)
25
    {
26
        if (null !== $this->nextStrategy) {
27
            return $this->nextStrategy->execute($object);
28
        }
29
30
        return null;
31
    }
32
}
33