/vendor/phpspec/prophecy/src/Prophecy/Argument/Token/IdenticalValueToken.php

https://bitbucket.org/alan_cordova/api-sb-map · PHP · 74 lines · 29 code · 9 blank · 36 comment · 1 complexity · d2ee5490e286d64a4e4d8be7309b0d71 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of the Prophecy.
  4. * (c) Konstantin Kudryashov <ever.zet@gmail.com>
  5. * Marcello Duarte <marcello.duarte@gmail.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 Prophecy\Argument\Token;
  11. use Prophecy\Util\StringUtil;
  12. /**
  13. * Identical value token.
  14. *
  15. * @author Florian Voutzinos <florian@voutzinos.com>
  16. */
  17. class IdenticalValueToken implements TokenInterface
  18. {
  19. private $value;
  20. private $string;
  21. private $util;
  22. /**
  23. * Initializes token.
  24. *
  25. * @param mixed $value
  26. * @param StringUtil $util
  27. */
  28. public function __construct($value, StringUtil $util = null)
  29. {
  30. $this->value = $value;
  31. $this->util = $util ?: new StringUtil();
  32. }
  33. /**
  34. * Scores 11 if argument matches preset value.
  35. *
  36. * @param $argument
  37. *
  38. * @return bool|int
  39. */
  40. public function scoreArgument($argument)
  41. {
  42. return $argument === $this->value ? 11 : false;
  43. }
  44. /**
  45. * Returns false.
  46. *
  47. * @return bool
  48. */
  49. public function isLast()
  50. {
  51. return false;
  52. }
  53. /**
  54. * Returns string representation for token.
  55. *
  56. * @return string
  57. */
  58. public function __toString()
  59. {
  60. if (null === $this->string) {
  61. $this->string = sprintf('identical(%s)', $this->util->stringify($this->value));
  62. }
  63. return $this->string;
  64. }
  65. }