Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
email
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
8
100.00% covered (success)
100.00%
1 / 1
 get_type
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_user_column
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 prepare_for_storage
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
6
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\ban\type;
15
16use phpbb\ban\exception\no_valid_emails_exception;
17
18class email extends base
19{
20    /**
21     * {@inheritDoc}
22     */
23    public function get_type(): string
24    {
25        return 'email';
26    }
27
28    /**
29     * {@inheritDoc}
30     */
31    public function get_user_column(): ?string
32    {
33        return 'user_email';
34    }
35
36    /**
37     * {@inheritDoc}
38     */
39    public function prepare_for_storage(array $items): array
40    {
41        $this->get_excluded();
42
43        $regex = '#^.*?@.*|(([a-z0-9\-]+\.)+([a-z]{2,3}))$#i';
44
45        $ban_items = [];
46        foreach ($items as $item)
47        {
48            $item = trim($item);
49            if (strlen($item) > 100 || !preg_match($regex, $item) || in_array($item, $this->excluded))
50            {
51                continue;
52            }
53            $ban_items[] = $item;
54        }
55
56        if (empty($ban_items))
57        {
58            throw new no_valid_emails_exception('NO_EMAILS_DEFINED');
59        }
60
61        return $ban_items;
62    }
63}