FixerFileProcessedEvent.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS;
  11. use Symfony\Component\EventDispatcher\Event;
  12. /**
  13. * Event that is fired when file was processed by Fixer.
  14. *
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. */
  17. class FixerFileProcessedEvent extends Event
  18. {
  19. /**
  20. * Event name.
  21. */
  22. const NAME = 'fixer.file_processed';
  23. const STATUS_UNKNOWN = 0;
  24. const STATUS_INVALID = 1;
  25. const STATUS_SKIPPED = 2;
  26. const STATUS_NO_CHANGES = 3;
  27. const STATUS_FIXED = 4;
  28. const STATUS_EXCEPTION = 5;
  29. const STATUS_LINT = 6;
  30. /**
  31. * File statuses map.
  32. *
  33. * @var array
  34. */
  35. private static $statusMap = array(
  36. self::STATUS_UNKNOWN => array('symbol' => '?', 'description' => 'unknown'),
  37. self::STATUS_INVALID => array('symbol' => 'I', 'description' => 'invalid file syntax, file ignored'),
  38. self::STATUS_SKIPPED => array('symbol' => '', 'description' => ''),
  39. self::STATUS_NO_CHANGES => array('symbol' => '.', 'description' => 'no changes'),
  40. self::STATUS_FIXED => array('symbol' => 'F', 'description' => 'fixed'),
  41. self::STATUS_EXCEPTION => array('symbol' => 'E', 'description' => 'error'),
  42. self::STATUS_LINT => array('symbol' => 'E', 'description' => 'error'),
  43. );
  44. /**
  45. * File status.
  46. *
  47. * @var int
  48. */
  49. private $status = self::STATUS_UNKNOWN;
  50. /**
  51. * Create instance.
  52. *
  53. * @return FixerFileProcessedEvent
  54. */
  55. public static function create()
  56. {
  57. return new static();
  58. }
  59. /**
  60. * Get status map.
  61. *
  62. * @return array
  63. */
  64. public static function getStatusMap()
  65. {
  66. return self::$statusMap;
  67. }
  68. /**
  69. * Get status.
  70. *
  71. * @return int
  72. */
  73. public function getStatus()
  74. {
  75. return $this->status;
  76. }
  77. /**
  78. * Get status as string.
  79. *
  80. * @return string
  81. */
  82. public function getStatusAsString()
  83. {
  84. return self::$statusMap[$this->status]['symbol'];
  85. }
  86. /**
  87. * Set status.
  88. *
  89. * @param int $status
  90. *
  91. * @return FixerFileProcessedEvent
  92. */
  93. public function setStatus($status)
  94. {
  95. $this->status = $status;
  96. return $this;
  97. }
  98. }