Skip to content

Commit 13aade2

Browse files
Initial work on value objects for #519
1 parent ba3057c commit 13aade2

11 files changed

+686
-0
lines changed

src/Target/Class_.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 SebastianBergmann\CodeCoverage\Test\Target;
11+
12+
/**
13+
* @immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
16+
*/
17+
final class Class_ extends Target
18+
{
19+
/**
20+
* @var class-string
21+
*/
22+
private string $className;
23+
24+
/**
25+
* @param class-string $className
26+
*/
27+
protected function __construct(string $className)
28+
{
29+
$this->className = $className;
30+
}
31+
32+
public function isClass(): true
33+
{
34+
return true;
35+
}
36+
37+
/**
38+
* @return class-string
39+
*/
40+
public function className(): string
41+
{
42+
return $this->className;
43+
}
44+
}

src/Target/ClassesThatExtendClass.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 SebastianBergmann\CodeCoverage\Test\Target;
11+
12+
/**
13+
* @immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
16+
*/
17+
final class ClassesThatExtendClass extends Target
18+
{
19+
/**
20+
* @var class-string
21+
*/
22+
private string $className;
23+
24+
/**
25+
* @param class-string $className
26+
*/
27+
protected function __construct(string $className)
28+
{
29+
$this->className = $className;
30+
}
31+
32+
public function isClassesThatExtendClass(): true
33+
{
34+
return true;
35+
}
36+
37+
/**
38+
* @return class-string
39+
*/
40+
public function className(): string
41+
{
42+
return $this->className;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 SebastianBergmann\CodeCoverage\Test\Target;
11+
12+
/**
13+
* @immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
16+
*/
17+
final class ClassesThatImplementInterface extends Target
18+
{
19+
/**
20+
* @var class-string
21+
*/
22+
private string $interfaceName;
23+
24+
/**
25+
* @param class-string $interfaceName
26+
*/
27+
protected function __construct(string $interfaceName)
28+
{
29+
$this->interfaceName = $interfaceName;
30+
}
31+
32+
public function isClassesThatImplementInterface(): true
33+
{
34+
return true;
35+
}
36+
37+
/**
38+
* @return class-string
39+
*/
40+
public function interfaceName(): string
41+
{
42+
return $this->interfaceName;
43+
}
44+
}

src/Target/Function_.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 SebastianBergmann\CodeCoverage\Test\Target;
11+
12+
/**
13+
* @immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
16+
*/
17+
final class Function_ extends Target
18+
{
19+
/**
20+
* @var non-empty-string
21+
*/
22+
private string $functionName;
23+
24+
/**
25+
* @param non-empty-string $functionName
26+
*/
27+
protected function __construct(string $functionName)
28+
{
29+
$this->functionName = $functionName;
30+
}
31+
32+
public function isFunction(): true
33+
{
34+
return true;
35+
}
36+
37+
/**
38+
* @return non-empty-string
39+
*/
40+
public function functionName(): string
41+
{
42+
return $this->functionName;
43+
}
44+
}

src/Target/Method.php

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 SebastianBergmann\CodeCoverage\Test\Target;
11+
12+
/**
13+
* @immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
16+
*/
17+
final class Method extends Target
18+
{
19+
/**
20+
* @var class-string
21+
*/
22+
private string $className;
23+
24+
/**
25+
* @var non-empty-string
26+
*/
27+
private string $methodName;
28+
29+
/**
30+
* @param class-string $className
31+
* @param non-empty-string $methodName
32+
*/
33+
protected function __construct(string $className, string $methodName)
34+
{
35+
$this->className = $className;
36+
$this->methodName = $methodName;
37+
}
38+
39+
public function isMethod(): true
40+
{
41+
return true;
42+
}
43+
44+
/**
45+
* @return class-string
46+
*/
47+
public function className(): string
48+
{
49+
return $this->className;
50+
}
51+
52+
/**
53+
* @return non-empty-string
54+
*/
55+
public function methodName(): string
56+
{
57+
return $this->methodName;
58+
}
59+
}

src/Target/Namespace_.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 SebastianBergmann\CodeCoverage\Test\Target;
11+
12+
/**
13+
* @immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
16+
*/
17+
final class Namespace_ extends Target
18+
{
19+
/**
20+
* @var non-empty-string
21+
*/
22+
private string $namespace;
23+
24+
/**
25+
* @param non-empty-string $namespace
26+
*/
27+
protected function __construct(string $namespace)
28+
{
29+
$this->namespace = $namespace;
30+
}
31+
32+
public function isNamespace(): true
33+
{
34+
return true;
35+
}
36+
37+
/**
38+
* @return non-empty-string
39+
*/
40+
public function namespace(): string
41+
{
42+
return $this->namespace;
43+
}
44+
}

src/Target/Target.php

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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 SebastianBergmann\CodeCoverage\Test\Target;
11+
12+
/**
13+
* @immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
16+
*/
17+
abstract class Target
18+
{
19+
/**
20+
* @param non-empty-string $namespace
21+
*/
22+
public static function forNamespace(string $namespace): Namespace_
23+
{
24+
return new Namespace_($namespace);
25+
}
26+
27+
/**
28+
* @param class-string $className
29+
*/
30+
public static function forClass(string $className): Class_
31+
{
32+
return new Class_($className);
33+
}
34+
35+
/**
36+
* @param class-string $className
37+
* @param non-empty-string $methodName
38+
*/
39+
public static function forMethod(string $className, string $methodName): Method
40+
{
41+
return new Method($className, $methodName);
42+
}
43+
44+
/**
45+
* @param class-string $interfaceName
46+
*/
47+
public static function forClassesThatImplementInterface(string $interfaceName): ClassesThatImplementInterface
48+
{
49+
return new ClassesThatImplementInterface($interfaceName);
50+
}
51+
52+
/**
53+
* @param class-string $className
54+
*/
55+
public static function forClassesThatExtendClass(string $className): ClassesThatExtendClass
56+
{
57+
return new ClassesThatExtendClass($className);
58+
}
59+
60+
/**
61+
* @param non-empty-string $functionName
62+
*/
63+
public static function forFunction(string $functionName): Function_
64+
{
65+
return new Function_($functionName);
66+
}
67+
68+
public function isNamespace(): bool
69+
{
70+
return false;
71+
}
72+
73+
public function isClass(): bool
74+
{
75+
return false;
76+
}
77+
78+
public function isMethod(): bool
79+
{
80+
return false;
81+
}
82+
83+
public function isClassesThatImplementInterface(): bool
84+
{
85+
return false;
86+
}
87+
88+
public function isClassesThatExtendClass(): bool
89+
{
90+
return false;
91+
}
92+
93+
public function isFunction(): bool
94+
{
95+
return false;
96+
}
97+
}

0 commit comments

Comments
 (0)