Complexity.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/complexity.
  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 SebastianBergmann\Complexity;
  11. use function str_contains;
  12. /**
  13. * @psalm-immutable
  14. */
  15. final class Complexity
  16. {
  17. /**
  18. * @psalm-var non-empty-string
  19. */
  20. private readonly string $name;
  21. /**
  22. * @psalm-var positive-int
  23. */
  24. private int $cyclomaticComplexity;
  25. /**
  26. * @psalm-param non-empty-string $name
  27. * @psalm-param positive-int $cyclomaticComplexity
  28. */
  29. public function __construct(string $name, int $cyclomaticComplexity)
  30. {
  31. $this->name = $name;
  32. $this->cyclomaticComplexity = $cyclomaticComplexity;
  33. }
  34. /**
  35. * @psalm-return non-empty-string
  36. */
  37. public function name(): string
  38. {
  39. return $this->name;
  40. }
  41. /**
  42. * @psalm-return positive-int
  43. */
  44. public function cyclomaticComplexity(): int
  45. {
  46. return $this->cyclomaticComplexity;
  47. }
  48. public function isFunction(): bool
  49. {
  50. return !$this->isMethod();
  51. }
  52. public function isMethod(): bool
  53. {
  54. return str_contains($this->name, '::');
  55. }
  56. }