Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created

Addon::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
nc 1
nop 0
dl 0
loc 12
ccs 0
cts 11
cp 0
crap 6
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Addons;
4
5
use ReflectionClass;
6
7
/**
8
 * @property string $id
9
 * @property string $slug
10
 * @property string $update_url
11
 */
12
abstract class Addon
13
{
14
    const ID = '';
15
    const SLUG = '';
16
    const UPDATE_URL = '';
17
18
    public $file;
19
    public $languages;
20
    public $name;
21
    public $testedTo;
22
    public $updater;
23
    public $version;
24
25
    public function __construct()
26
    {
27
        $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName());
28
        $plugin = get_file_data($this->file, [
29
            'languages' => 'Domain Path',
30
            'name' => 'Plugin Name',
31
            'testedTo' => 'Tested up to',
32
            'version' => 'Version',
33
        ], 'plugin');
34
        array_walk($plugin, function ($value, $key) {
35
            if (property_exists($this, $key)) {
36
                $this->$key = $value;
37
            }
38
        });
39
    }
40
41
    /**
42
     * @param string $property
43
     * @return void|string
44
     */
45
    public function __get($property)
46
    {
47
        if (property_exists($this, $property)) {
48
            return $this->$property;
49
        }
50
        $constant = 'static::'.strtoupper($property);
51
        if (defined($constant)) {
52
            return constant($constant);
53
        }
54
    }
55
56
    public function make($class)
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

56
    public function make(/** @scrutinizer ignore-unused */ $class)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {}
58
59
    /**
60
     * @return void
61
     */
62
    abstract public function init();
63
64
    /**
65
     * @param string $file
66
     * @return string
67
     */
68
    public function path($file = '')
69
    {
70
        return plugin_dir_path($this->file).ltrim(trim($file), '/');
71
    }
72
73
    /**
74
     * @return void
75
     */
76
    public function update()
77
    {
78
        $this->updater = new Updater(static::UPDATE_URL, $this->file, [
79
            'license' => glsr_get_option('settings.licenses.'.static::ID),
80
            'testedTo' => $this->testedTo,
81
        ]);
82
        $this->updater->init();
83
    }
84
85
    /**
86
     * @param string $path
87
     * @return string
88
     */
89
    public function url($path = '')
90
    {
91
        return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/'));
92
    }
93
}
94