Repository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 45
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A collect() 0 13 2
read() 0 1 ?
1
<?php
2
3
namespace RichanFongdasen\I18n\Repositories;
4
5
use Illuminate\Support\Collection;
6
use RichanFongdasen\I18n\Locale;
7
8
abstract class Repository
9
{
10
    /**
11
     * Language data source.
12
     *
13
     * @var string
14
     */
15
    protected $datasource;
16
17
    /**
18
     * Class constructor.
19
     *
20
     * @param string $datasource
21
     */
22
    public function __construct($datasource)
23
    {
24
        $this->datasource = $datasource;
25
    }
26
27
    /**
28
     * Get language collection.
29
     *
30
     * @return \Illuminate\Support\Collection
31
     */
32
    public function collect(): Collection
33
    {
34
        $collection = collect();
35
36
        foreach ($this->read() as $locale) {
37
            $collection->put(
38
                $locale->language,
39
                new Locale($locale->name, $locale->language, $locale->country)
40
            );
41
        }
42
43
        return $collection;
44
    }
45
46
    /**
47
     * Read the datasource.
48
     *
49
     * @return mixed
50
     */
51
    abstract protected function read();
52
}
53