Code Duplication    Length = 20-20 lines in 2 locations

src/ConfigTree/FileParsing/Formats/IniFile.php 1 location

@@ 7-26 (lines=20) @@
4
use ConfigTree\FileParsing\ArrayableFile;
5
use ConfigTree\FileParsing\Reading\FileContentsRetriever;
6
7
class IniFile implements ArrayableFile
8
{
9
    /** @var string */
10
    private $path;
11
12
    /** @var FileContentsRetriever */
13
    private $fileContentsRetriever;
14
15
    public function __construct(string $path, FileContentsRetriever $fileContentsRetriever)
16
    {
17
        $this->path = $path;
18
        $this->fileContentsRetriever = $fileContentsRetriever;
19
    }
20
21
    public function toArray() : array
22
    {
23
        $fileContents = $this->fileContentsRetriever->fileGetContents($this->path);
24
        return parse_ini_string($fileContents);
25
    }
26
}
27

src/ConfigTree/FileParsing/Formats/JsonFile.php 1 location

@@ 7-26 (lines=20) @@
4
use ConfigTree\FileParsing\ArrayableFile;
5
use ConfigTree\FileParsing\Reading\FileContentsRetriever;
6
7
class JsonFile implements ArrayableFile
8
{
9
    /** @var string */
10
    private $path;
11
12
    /** @var FileContentsRetriever */
13
    private $fileContentsRetriever;
14
15
    public function __construct(string $path, FileContentsRetriever $fileContentsRetriever)
16
    {
17
        $this->path = $path;
18
        $this->fileContentsRetriever = $fileContentsRetriever;
19
    }
20
21
    public function toArray() : array
22
    {
23
        $fileContents = $this->fileContentsRetriever->fileGetContents($this->path);
24
        return json_decode($fileContents, true);
25
    }
26
}
27