Completed
Branch master (e25020)
by Richan
03:06
created

Repository   A

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