Passed
Push — master ( 7e3913...f58fec )
by Sebastian
05:25
created

Localization_Source::countUntranslated()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 14
rs 10
1
<?php
2
/**
3
 * File containing the class {@see \AppLocalize\Localization_Source}.
4
 *
5
 * @package Localization
6
 * @subpackage Parser
7
 * @see \AppLocalize\Localization_Source
8
 */
9
10
declare(strict_types=1);
11
12
namespace AppLocalize;
13
14
/**
15
 * Base source class for a location that stores texts to translate.
16
 * This can be from the file system, as well as a database for example.
17
 * Each source type must extend this class.
18
 *
19
 * Sources are added manually when configuring the localization layer.
20
 * See for example {@see Localization::addSourceFolder()}.
21
 *
22
 * @package Localization
23
 * @subpackage Parser
24
 * @author Sebastian Mordziol <[email protected]>
25
 *
26
 * @see Localization_Source_Folder
27
 */
28
abstract class Localization_Source
29
{
30
   /**
31
    * Human-readable label for the source.
32
    * @var string
33
    */
34
    protected $label;
35
    
36
   /**
37
    * Human-readable group name to categorize the source.
38
    * @var string
39
    */
40
    protected $group;
41
    
42
   /**
43
    * The folder in which the localization files are stored
44
    * @var string
45
    */
46
    protected $storageFolder;
47
    
48
   /**
49
    * @var string
50
    */
51
    protected $alias;
52
53
    public function __construct(string $alias, string $label, string $group, string $storageFolder)
54
    {
55
        $this->alias = $alias;
56
        $this->label = $label;
57
        $this->group = $group;
58
        $this->storageFolder = $storageFolder;
59
    }
60
    
61
    abstract public function getID() : string;
62
    
63
    public function getAlias() : string
64
    {
65
        return $this->alias;
66
    }
67
    
68
    public function getLabel() : string
69
    {
70
        return $this->label;
71
    }
72
    
73
    public function getGroup() : string
74
    {
75
        return $this->group;
76
    }
77
    
78
    public function getStorageFolder() : string
79
    {
80
        return $this->storageFolder;
81
    }
82
    
83
    public function scan(Localization_Scanner $scanner) : void
84
    {
85
        $this->_scan($this->getSourceScanner($scanner));
86
    }
87
88
    /**
89
     * Retrieves the scanner instance that can access this
90
     * source's string hashes and parsing methods.
91
     *
92
     * @param Localization_Scanner $scanner
93
     * @return Localization_Source_Scanner
94
     */
95
    public function getSourceScanner(Localization_Scanner $scanner) : Localization_Source_Scanner
96
    {
97
        return new Localization_Source_Scanner($this, $scanner);
98
    }
99
    
100
    abstract protected function _scan(Localization_Source_Scanner $scanner) : void;
101
102
    protected function log(string $message) : void
103
    {
104
        Localization::log(sprintf(
105
            'Source [%s] | %s',
106
            $this->getID(),
107
            $message
108
        ));
109
    }
110
}
111