1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Coverage information for PHPUnit.
19 *
20 * @package    core
21 * @category   phpunit
22 * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
23 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28/**
29 * Coverage information for PHPUnit.
30 *
31 * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
32 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 */
34class phpunit_coverage_info {
35
36    /** @var array The list of folders relative to the plugin root to whitelist in coverage generation. */
37    protected $whitelistfolders = [];
38
39    /** @var array The list of files relative to the plugin root to whitelist in coverage generation. */
40    protected $whitelistfiles = [];
41
42    /** @var array The list of folders relative to the plugin root to excludelist in coverage generation. */
43    protected $excludelistfolders = [];
44
45    /** @var array The list of files relative to the plugin root to excludelist in coverage generation. */
46    protected $excludelistfiles = [];
47
48    /**
49     * Get the formatted XML list of files and folders to whitelist.
50     *
51     * @param   string  $plugindir The root of the plugin, relative to the dataroot.
52     * @return  array
53     */
54    final public function get_whitelists(string $plugindir) : array {
55        $filters = [];
56
57        if (!empty($plugindir)) {
58            $plugindir .= "/";
59        }
60
61        foreach ($this->whitelistfolders as $folder) {
62            $filters[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
63        }
64
65        foreach ($this->whitelistfiles as $file) {
66            $filters[] = html_writer::tag('file', "{$plugindir}{$file}");
67        }
68
69        return $filters;
70    }
71
72    /**
73     * Get the formatted XML list of files and folders to exclude.
74     *
75     * @param   string  $plugindir The root of the plugin, relative to the dataroot.
76     * @return  array
77     */
78    final public function get_excludelists(string $plugindir) : array {
79        $filters = [];
80
81        if (!empty($plugindir)) {
82            $plugindir .= "/";
83        }
84
85        foreach ($this->excludelistfolders as $folder) {
86            $filters[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
87        }
88
89        foreach ($this->excludelistfiles as $file) {
90            $filters[] = html_writer::tag('file', "{$plugindir}{$file}");
91        }
92
93        return $filters;
94    }
95}
96