Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
handler_factory
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_instance
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\report;
15
16use phpbb\report\exception\factory_invalid_argument_exception;
17
18class handler_factory
19{
20    /**
21     * @var \Symfony\Component\DependencyInjection\ContainerInterface
22     */
23    protected $container;
24
25    /**
26     * Constructor
27     *
28     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
29     */
30    public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container)
31    {
32        $this->container = $container;
33    }
34
35    /**
36     * Return a new instance of an appropriate report handler
37     *
38     * @param string    $type
39     * @return report_handler_interface
40     * @throws factory_invalid_argument_exception if $type is not valid
41     */
42    public function get_instance($type)
43    {
44        $report_handler = null;
45        switch ($type)
46        {
47            case 'pm':
48                $report_handler = $this->container->get('phpbb.report.handlers.report_handler_pm');
49            break;
50
51            case 'post':
52                $report_handler =  $this->container->get('phpbb.report.handlers.report_handler_post');
53            break;
54        }
55
56        if ($report_handler instanceof report_handler_interface)
57        {
58            return $report_handler;
59        }
60
61        throw new factory_invalid_argument_exception();
62    }
63}