Skip to content

Commit

Permalink
Initial work on value objects for #519
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 28, 2024
1 parent ceaeeea commit 6c6209f
Show file tree
Hide file tree
Showing 11 changed files with 686 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Target/Class_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Test\Target;

/**
* @immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
final class Class_ extends Target
{
/**
* @var class-string
*/
private string $className;

/**
* @param class-string $className
*/
protected function __construct(string $className)
{
$this->className = $className;
}

public function isClass(): true
{
return true;
}

/**
* @return class-string
*/
public function className(): string
{
return $this->className;
}
}
44 changes: 44 additions & 0 deletions src/Target/ClassesThatExtendClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Test\Target;

/**
* @immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
final class ClassesThatExtendClass extends Target
{
/**
* @var class-string
*/
private string $className;

/**
* @param class-string $className
*/
protected function __construct(string $className)
{
$this->className = $className;
}

public function isClassesThatExtendClass(): true
{
return true;
}

/**
* @return class-string
*/
public function className(): string
{
return $this->className;
}
}
44 changes: 44 additions & 0 deletions src/Target/ClassesThatImplementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Test\Target;

/**
* @immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
final class ClassesThatImplementInterface extends Target
{
/**
* @var class-string
*/
private string $interfaceName;

/**
* @param class-string $interfaceName
*/
protected function __construct(string $interfaceName)
{
$this->interfaceName = $interfaceName;
}

public function isClassesThatImplementInterface(): true
{
return true;
}

/**
* @return class-string
*/
public function interfaceName(): string
{
return $this->interfaceName;
}
}
44 changes: 44 additions & 0 deletions src/Target/Function_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Test\Target;

/**
* @immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
final class Function_ extends Target
{
/**
* @var non-empty-string
*/
private string $functionName;

/**
* @param non-empty-string $functionName
*/
protected function __construct(string $functionName)
{
$this->functionName = $functionName;
}

public function isFunction(): true
{
return true;
}

/**
* @return non-empty-string
*/
public function functionName(): string
{
return $this->functionName;
}
}
59 changes: 59 additions & 0 deletions src/Target/Method.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Test\Target;

/**
* @immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
final class Method extends Target
{
/**
* @var class-string
*/
private string $className;

/**
* @var non-empty-string
*/
private string $methodName;

/**
* @param class-string $className
* @param non-empty-string $methodName
*/
protected function __construct(string $className, string $methodName)
{
$this->className = $className;
$this->methodName = $methodName;
}

public function isMethod(): true
{
return true;
}

/**
* @return class-string
*/
public function className(): string
{
return $this->className;
}

/**
* @return non-empty-string
*/
public function methodName(): string
{
return $this->methodName;
}
}
44 changes: 44 additions & 0 deletions src/Target/Namespace_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Test\Target;

/**
* @immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
final class Namespace_ extends Target
{
/**
* @var non-empty-string
*/
private string $namespace;

/**
* @param non-empty-string $namespace
*/
protected function __construct(string $namespace)
{
$this->namespace = $namespace;
}

public function isNamespace(): true
{
return true;
}

/**
* @return non-empty-string
*/
public function namespace(): string
{
return $this->namespace;
}
}
97 changes: 97 additions & 0 deletions src/Target/Target.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Test\Target;

/**
* @immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
abstract class Target
{
/**
* @param non-empty-string $namespace
*/
public static function forNamespace(string $namespace): Namespace_
{
return new Namespace_($namespace);
}

/**
* @param class-string $className
*/
public static function forClass(string $className): Class_
{
return new Class_($className);
}

/**
* @param class-string $className
* @param non-empty-string $methodName
*/
public static function forMethod(string $className, string $methodName): Method
{
return new Method($className, $methodName);
}

/**
* @param class-string $interfaceName
*/
public static function forClassesThatImplementInterface(string $interfaceName): ClassesThatImplementInterface
{
return new ClassesThatImplementInterface($interfaceName);
}

/**
* @param class-string $className
*/
public static function forClassesThatExtendClass(string $className): ClassesThatExtendClass
{
return new ClassesThatExtendClass($className);
}

/**
* @param non-empty-string $functionName
*/
public static function forFunction(string $functionName): Function_
{
return new Function_($functionName);
}

public function isNamespace(): bool
{
return false;
}

public function isClass(): bool
{
return false;
}

public function isMethod(): bool
{
return false;
}

public function isClassesThatImplementInterface(): bool
{
return false;
}

public function isClassesThatExtendClass(): bool
{
return false;
}

public function isFunction(): bool
{
return false;
}
}
Loading

0 comments on commit 6c6209f

Please sign in to comment.