Passed
Push — master ( f6e115...dbae53 )
by Hector Luis
04:48
created

Singleton   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
c 1
b 0
f 0
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A singleton() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Decorator Implementation
6
 * @category    Ticaje
7
 * @author      Max Demian <[email protected]>
8
 */
9
10
namespace Ticaje\Contract\Traits;
11
12
/**
13
 * Trait Singleton
14
 * @package Ticaje\Contract\Traits
15
 * This trait accomplishes singleton pattern to those classes that require to momentarily cache a result based on current execution thread.
16
 */
17
trait Singleton
18
{
19
    /**
20
     * @param $binder // The binder is a class property, preferably a protected/private one
0 ignored issues
show
Documentation Bug introduced by
The doc comment // at position 0 could not be parsed: Unknown type name '//' at position 0 in //.
Loading history...
21
     * @param callable $logic
22
     * @return mixed
23
     */
24
    protected function singleton($binder, callable $logic)
25
    {
26
        if (!$this->{$binder}) {
27
            $this->{$binder} = $logic();
28
        }
29
        return $this->{$binder};
30
    }
31
}
32