Passed
Push — master ( c4a808...c45372 )
by Gabriel
15:08
created

HasTranslationTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 12
c 1
b 0
f 1
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generateLabel() 0 3 1
A generateLabelShort() 0 3 1
A getLabel() 0 10 4
A translate() 0 4 2
1
<?php
2
3
namespace ByTIC\Models\SmartProperties\Properties\AbstractProperty\Traits;
4
5
trait HasTranslationTrait
6
{
7
8
    protected $label = null;
9
10
    protected $label_short = null;
11
12
13
    /**
14
     * Get Property label
15
     *
16
     * @param bool $short short flag
17
     *
18
     * @return null
19
     */
20
    public function getLabel($short = false)
21
    {
22
        if (!$this->label) {
23
            $this->label = $this->generateLabel();
24
            if ($this->hasShortLabel()) {
0 ignored issues
show
Bug introduced by
It seems like hasShortLabel() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
            if ($this->/** @scrutinizer ignore-call */ hasShortLabel()) {
Loading history...
25
                $this->label_short = $this->generateLabelShort();
26
            }
27
        }
28
29
        return $short ? $this->label_short : $this->label;
30
    }
31
32
    /**
33
     * @param string $slug
34
     * @return string
35
     */
36
    public function translate($slug = '', $params = [])
37
    {
38
        $slug = empty($slug) ? $slug : '.' . $slug;
39
        return $this->getManager()->translate($this->getLabelSlug() . '.' . $this->getName() . $slug, $params);
0 ignored issues
show
Bug introduced by
It seems like getManager() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

39
        return $this->/** @scrutinizer ignore-call */ getManager()->translate($this->getLabelSlug() . '.' . $this->getName() . $slug, $params);
Loading history...
Bug introduced by
It seems like getName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

39
        return $this->getManager()->translate($this->getLabelSlug() . '.' . $this->/** @scrutinizer ignore-call */ getName() . $slug, $params);
Loading history...
Bug introduced by
The method getLabelSlug() does not exist on ByTIC\Models\SmartProper...its\HasTranslationTrait. Did you maybe mean getLabel()? ( Ignorable by Annotation )

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

39
        return $this->getManager()->translate($this->/** @scrutinizer ignore-call */ getLabelSlug() . '.' . $this->getName() . $slug, $params);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    protected function generateLabel()
46
    {
47
        return $this->translate();
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    protected function generateLabelShort()
54
    {
55
        return $this->translate('short');
56
    }
57
}