Passed
Branch master (da5350)
by Timur
02:19
created

Text::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Murtukov\PHPCodeGenerator;
6
7
class Text extends AbstractGenerator
8
{
9
    public string $value;
10
    public bool $doubleQuotes;
11
12
    public function __construct(string $value, bool $doubleQuotes = false)
13
    {
14
        $this->value = $value;
15
        $this->doubleQuotes = $doubleQuotes;
16
    }
17
18
    public static function new(string $value, bool $doubleQuotes = false): self
19
    {
20
        return new self($value, $doubleQuotes);
21
    }
22
23
    public function generate(): string
24
    {
25
        if ($this->doubleQuotes) {
26
            return '"'.$this->value.'"';
27
        } else {
28
            return "'$this->value'";
29
        }
30
    }
31
}
32