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

Repository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 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