DeprecationGroup.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
  11. /**
  12. * @internal
  13. */
  14. final class DeprecationGroup
  15. {
  16. private $count = 0;
  17. /**
  18. * @var DeprecationNotice[] keys are messages
  19. */
  20. private $deprecationNotices = [];
  21. /**
  22. * @param string $message
  23. * @param string $class
  24. * @param string $method
  25. */
  26. public function addNoticeFromObject($message, $class, $method)
  27. {
  28. $this->deprecationNotice($message)->addObjectOccurrence($class, $method);
  29. $this->addNotice();
  30. }
  31. /**
  32. * @param string $message
  33. */
  34. public function addNoticeFromProceduralCode($message)
  35. {
  36. $this->deprecationNotice($message)->addProceduralOccurrence();
  37. $this->addNotice();
  38. }
  39. public function addNotice()
  40. {
  41. ++$this->count;
  42. }
  43. /**
  44. * @param string $message
  45. *
  46. * @return DeprecationNotice
  47. */
  48. private function deprecationNotice($message)
  49. {
  50. if (!isset($this->deprecationNotices[$message])) {
  51. $this->deprecationNotices[$message] = new DeprecationNotice();
  52. }
  53. return $this->deprecationNotices[$message];
  54. }
  55. public function count()
  56. {
  57. return $this->count;
  58. }
  59. public function notices()
  60. {
  61. return $this->deprecationNotices;
  62. }
  63. }