Completed
Pull Request — 1.2 (#12)
by David
08:23
created

RendererServiceProvider::createCustomRenderer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 3
1
<?php
2
3
4
namespace Mouf\Html\Renderer;
5
6
use Interop\Container\ServiceProviderInterface;
7
use PHPStan\Cache\Cache;
8
use Psr\Container\ContainerInterface;
9
use Psr\SimpleCache\CacheInterface;
10
use TheCodingMachine\Funky\Annotations\Factory;
11
use TheCodingMachine\Funky\Annotations\Tag;
12
use TheCodingMachine\Funky\ServiceProvider;
13
14
/**
15
 * This class can be extended to implement easily a service provider that creates "package level" renderers.
16
 */
17
class RendererServiceProvider extends ServiceProvider
18
{
19
    /**
20
     * @Factory(aliases={RendererInterface::class})
21
     * @return ChainRenderer
22
     */
23
    public static function createChainRenderer(ContainerInterface $container, CacheInterface $cache): ChainRenderer
24
    {
25
        return new ChainRenderer(
26
            $container,
27
            \iterator_to_array($container->get('customRenderers')),
28
            \iterator_to_array($container->get('packageRenderers')),
29
            $cache,
30
            'chainRenderer'
31
        );
32
    }
33
34
    /**
35
     * @Factory(name="customRenderer", tags={@Tag(name="customRenderers")})
36
     * @return FileBasedRenderer
37
     */
38
    public static function createCustomRenderer(ContainerInterface $container, CacheInterface $cache, \Twig_Environment $twig): FileBasedRenderer
39
    {
40
        return new FileBasedRenderer(\ComposerLocator::getRootPath().'/src/templates', $cache, $container, $twig);
0 ignored issues
show
Bug introduced by
The method getRootPath() does not seem to exist on object<ComposerLocator>.

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...
41
    }
42
43
    /**
44
     * @Factory(name="packageRenderers")
45
     * @return \SplPriorityQueue
46
     */
47
    public static function createPackageRenderers(): \SplPriorityQueue
48
    {
49
        return new \SplPriorityQueue();
50
    }
51
52
    /**
53
     * @Factory(name="customRenderers")
54
     * @return \SplPriorityQueue
55
     */
56
    public static function createCustomRenderers(): \SplPriorityQueue
57
    {
58
        return new \SplPriorityQueue();
59
    }
60
}
61