Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
35.71% covered (danger)
35.71%
5 / 14
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
factory
35.71% covered (danger)
35.71%
5 / 14
75.00% covered (warning)
75.00%
3 / 4
15.56
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_instance
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 garbage_collect
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_captcha_types
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
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\captcha;
15
16class factory
17{
18    /**
19    * @var \Symfony\Component\DependencyInjection\ContainerInterface
20    */
21    private $container;
22
23    /**
24    * @var \phpbb\di\service_collection
25    */
26    private $plugins;
27
28    /**
29    * Constructor
30    *
31    * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
32    * @param \phpbb\di\service_collection                              $plugins
33    */
34    public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, \phpbb\di\service_collection $plugins)
35    {
36        $this->container = $container;
37        $this->plugins = $plugins;
38    }
39
40    /**
41    * Return a new instance of a given plugin
42    *
43    * @param $name
44    * @return object|null
45    */
46    public function get_instance($name)
47    {
48        return $this->container->get($name);
49    }
50
51    /**
52    * Call the garbage collector
53    *
54    * @param string $name The name to the captcha service.
55    */
56    function garbage_collect($name)
57    {
58        $captcha = $this->get_instance($name);
59        $captcha->garbage_collect(0);
60    }
61
62    /**
63    * Return a list of all registered CAPTCHA plugins
64    *
65    * @returns array
66    */
67    function get_captcha_types()
68    {
69        $captchas = array(
70            'available'        => array(),
71            'unavailable'    => array(),
72        );
73
74        foreach ($this->plugins as $plugin => $plugin_instance)
75        {
76            if ($plugin_instance->is_available())
77            {
78                $captchas['available'][$plugin] = $plugin_instance->get_name();
79            }
80            else
81            {
82                $captchas['unavailable'][$plugin] = $plugin_instance->get_name();
83            }
84        }
85
86        return $captchas;
87    }
88}