Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Framework\Constraint;
11
 
12
use function sprintf;
13
use PHPUnit\Framework\Exception;
14
use ReflectionClass;
15
use ReflectionException;
16
 
17
/**
18
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
19
 */
20
final class ClassHasStaticAttribute extends ClassHasAttribute
21
{
22
    /**
23
     * Returns a string representation of the constraint.
24
     */
25
    public function toString(): string
26
    {
27
        return sprintf(
28
            'has static attribute "%s"',
29
            $this->attributeName()
30
        );
31
    }
32
 
33
    /**
34
     * Evaluates the constraint for parameter $other. Returns true if the
35
     * constraint is met, false otherwise.
36
     *
37
     * @param mixed $other value or object to evaluate
38
     */
39
    protected function matches($other): bool
40
    {
41
        try {
42
            $class = new ReflectionClass($other);
43
 
44
            if ($class->hasProperty($this->attributeName())) {
45
                return $class->getProperty($this->attributeName())->isStatic();
46
            }
47
            // @codeCoverageIgnoreStart
48
        } catch (ReflectionException $e) {
49
            throw new Exception(
50
                $e->getMessage(),
51
                $e->getCode(),
52
                $e
53
            );
54
        }
55
        // @codeCoverageIgnoreEnd
56
 
57
        return false;
58
    }
59
}