ParserGeneric::factory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of graze/unicontroller-client.
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/unicontroller-client/blob/master/LICENSE.md
11
 * @link https://github.com/graze/unicontroller-client
12
 */
13
namespace Graze\UnicontrollerClient\Parser\Parser;
14
15
use Graze\UnicontrollerClient\Parser\Parser\ParserInterface;
16
use Graze\UnicontrollerClient\Entity\EntityHydrator;
17
use Graze\UnicontrollerClient\Entity\Entity\EntityGeneric;
18
19
class ParserGeneric implements ParserInterface
20
{
21
    /**
22
     * @var EntityHydrator
23
     */
24
    private $entityHydrator;
25
26
    /**
27
     * @param EntityHydrator $entityHydrator
28
     */
29
    public function __construct(EntityHydrator $entityHydrator)
30
    {
31
        $this->entityHydrator = $entityHydrator;
32
    }
33
34
    /**
35
     * @param string $string
36
     * @return Graze\UnicontrollerClient\Entity\Entity\EntityInterface
0 ignored issues
show
Bug introduced by
The type Graze\UnicontrollerClien...\Entity\EntityInterface was not found. Did you mean Graze\UnicontrollerClien...\Entity\EntityInterface? If so, make sure to prefix the type with \.
Loading history...
37
     */
38
    public function parse($string)
39
    {
40
        return $this->entityHydrator->hydrate(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->entityHydr...s' => $string == ' ')) returns the type Graze\UnicontrollerClien...ty\Entity\EntityGeneric which is incompatible with the documented return type Graze\UnicontrollerClien...\Entity\EntityInterface.
Loading history...
41
            new EntityGeneric(),
42
            ['success' => $string == "\r\n"]
43
        );
44
    }
45
46
    /**
47
     * @return ParserGeneric
48
     */
49
    public static function factory()
50
    {
51
        return new static(
52
            new EntityHydrator()
53
        );
54
    }
55
}
56