AbstractRecipe::instance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\Air\Recipe;
6
7
/**
8
 * Base class of recipe
9
 */
10
abstract class AbstractRecipe implements RecipeInterface
11
{
12
    use RecipeTrait;
13
14
    /**
15
     * A fixed value
16
     *
17
     * @param mixed $value The value.
18
     * @return AbstractRecipe
19
     */
20 6
    public static function value($value): AbstractRecipe
21
    {
22 6
        return new FixedValueRecipe($value);
23
    }
24
25
    /**
26
     * Create a alias
27
     *
28
     * @param string $alias The alias string key.
29
     * @return AbstractRecipe
30
     */
31 1
    public static function alias(string $alias): AbstractRecipe
32
    {
33 1
        return new AliasRecipe($alias);
34
    }
35
36
    /**
37
     * Calls a builder method using factory.
38
     *
39
     * @param callable $builder The builder method. Its parameter will be injected as dependency.
40
     * @param array    $extra   Extra parameters.
41
     * @return AbstractRecipe
42
     */
43 2
    public static function builder(callable $builder, array $extra = []): AbstractRecipe
44
    {
45 2
        return new BuilderRecipe($builder, $extra);
46
    }
47
48
    /**
49
     * Populate an instance by factory
50
     *
51
     * @param string|null $className Optional classname. Can be ommited when the entry key is the classname.
52
     * @param array       $extra     Extra parameteres.
53
     * @return AbstractRecipe
54
     */
55 1
    public static function instance(?string $className = null, array $extra = []): AbstractRecipe
56
    {
57 1
        return new InstanceRecipe($className, $extra);
58
    }
59
60
    /**
61
     * Autowire this entry
62
     *
63
     * @param string $className The Classname.
64
     * @param array  $extra     Extra parameteres.
65
     * @param bool   $cached    Whether to save the instance if it's not defined in container.
66
     * @return AbstractRecipe
67
     */
68 2
    public static function autowire(string $className, array $extra = [], bool $cached = true): AbstractRecipe
69
    {
70 2
        return new AutowireRecipe($className, $extra, $cached);
71
    }
72
}
73