Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Network
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isBanned
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * The network class for IPv4 and IPv6 handling.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @author    Matteo Scaramuccia <matteo@phpmyfaq.de>
13 * @author    Kenneth Shaw <ken@expitrans.com>
14 * @author    David Soria Parra <dsp@php.net>
15 * @copyright 2011-2026 phpMyFAQ Team
16 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
17 * @link      https://www.phpmyfaq.de
18 * @since     2011-02-04
19 */
20
21declare(strict_types=1);
22
23namespace phpMyFAQ;
24
25use Symfony\Component\HttpFoundation\IpUtils;
26
27/**
28 * Class Network
29 *
30 * @package phpMyFAQ
31 */
32readonly class Network
33{
34    /**
35     * Constructor.
36     */
37    public function __construct(
38        private Configuration $configuration,
39    ) {
40    }
41
42    /**
43     * Performs a check if an IPv4 or IPv6 address is banned.
44     *
45     * @param string $ipAddress IPv4 or IPv6 address
46     * @return bool false, if not banned
47     */
48    public function isBanned(string $ipAddress): bool
49    {
50        $bannedIps = explode(separator: ' ', string: (string) $this->configuration->get(item: 'security.bannedIPs'));
51        return IpUtils::checkIp($ipAddress, $bannedIps);
52    }
53}