GitAski::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 5
1
<?php
2
3
namespace Kasifi\Gitaski;
4
5
use DateTime;
6
use Symfony\Component\Console\Style\SymfonyStyle;
7
8
class GitAski
9
{
10
    /** @var SymfonyStyle */
11
    private $io;
12
13
    /** @var GitProcessor */
14
    private $gitProcessor;
15
16
    /** @var DateTime */
17
    private $lastSunday;
18
19
    /**
20
     * Gitaski constructor.
21
     *
22
     * @param boolean $force
23
     * @param string  $githubRepositoryUrl
24
     * @param         $inputFilePath
25
     * @param         $outputFilename
26
     * @param array   $commitMessages
27
     */
28
    public function __construct($force, $githubRepositoryUrl, $inputFilePath, $outputFilename, array $commitMessages)
29
    {
30
        $this->gitProcessor= new GitProcessor($githubRepositoryUrl, $force, $inputFilePath, $outputFilename, $commitMessages);
31
32
        $date = new DateTime();
33
        $date->setTime(12, 0, 0);
34
        $this->lastSunday = $this->gitProcessor->getPreviousSunday($date);
35
    }
36
37
    /**
38
     * @param SymfonyStyle $io
39
     */
40
    public function setIo($io)
41
    {
42
        $this->io = $io;
43
        $this->gitProcessor->setIo($this->io);
44
    }
45
46
    public function writeText($str)
47
    {
48
        $this->gitProcessor->initLocalRepository();
49
50
        $asciiString = AsciiHelper::generateAsciiFromText($str);
51
52
        $this->io->note('Ascii string received:');
53
        $this->io->write($asciiString);
54
55
        $symbol = AsciiHelper::generateSymbolFromAsciiString($asciiString, ['#' => 2, ' ' => 1]);
56
57
        $this->write($symbol);
58
    }
59
60
    public function writeJson($filename)
61
    {
62
        $json = json_decode(file_get_contents(__DIR__ . '/' . $filename), true);
63
        $symbol = AsciiHelper::generateSymbolFromJson($json, [
64
            '#eeeeee' => 0,
65
            '#cdeb8b' => 1,
66
            '#6bba70' => 2,
67
            '#009938' => 3,
68
            '#006e2e' => 4,
69
        ]);
70
        $this->write($symbol);
71
    }
72
73
    public function clean() {
74
        $this->gitProcessor->clean();
75
    }
76
77
    /**
78
     * @param $symbol
79
     */
80
    private function write($symbol)
81
    {
82
        $this->io->note('Symbol to draw');
83
        $this->io->write(AsciiHelper::renderSymbol($symbol));
84
        $this->gitProcessor->writeSymbol($symbol, $this->lastSunday);
85
    }
86
}
87