Telefonica::findVersion()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.2728
c 0
b 0
f 0
cc 5
nc 5
nop 0
1
<?php
2
3
namespace Telefonica;
4
5
use Illuminate\Database\Eloquent\Collection;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Filesystem\Filesystem;
8
use Illuminate\Support\Arr;
9
use Illuminate\Support\Facades\Cache;
10
use Illuminate\Support\Facades\Storage;
11
use Illuminate\Support\Str;
12
use View;
13
use Config;
14
use Request;
15
use Session;
16
use ReflectionClass;
17
18
use Crypto;
19
20
class Telefonica
21
{
22
    protected $version;
23
    protected $filesystem;
24
25
    /**
26
     * The current locale, cached in memory
27
     *
28
     * @var string
29
     */
30
    private $locale;
31
32
    public function __construct()
33
    {
34
        $this->filesystem = app(Filesystem::class);
35
36
        $this->findVersion();
37
    }
38
39
    public function getVersion()
40
    {
41
        return $this->version;
42
    }
43
44
    protected function findVersion()
45
    {
46
        if (!is_null($this->version)) {
47
            return;
48
        }
49
50
        if ($this->filesystem->exists(base_path('composer.lock'))) {
51
            // Get the composer.lock file
52
            $file = json_decode(
53
                $this->filesystem->get(base_path('composer.lock'))
54
            );
55
56
            // Loop through all the packages and get the version of telefonica
57
            foreach ($file->packages as $package) {
58
                if ($package->name == 'sierratecnologia/telefonica') {
59
                    $this->version = $package->version;
60
                    break;
61
                }
62
            }
63
        }
64
    }
65
}
66