1<?php
2
3/*
4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 *     Marcello Duarte <marcello.duarte@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Prophecy\Argument\Token;
13
14/**
15 * String contains token.
16 *
17 * @author Peter Mitchell <pete@peterjmit.com>
18 */
19class StringContainsToken implements TokenInterface
20{
21    private $value;
22
23    /**
24     * Initializes token.
25     *
26     * @param string $value
27     */
28    public function __construct($value)
29    {
30        $this->value = $value;
31    }
32
33    public function scoreArgument($argument)
34    {
35        return is_string($argument) && strpos($argument, $this->value) !== false ? 6 : false;
36    }
37
38    /**
39     * Returns preset value against which token checks arguments.
40     *
41     * @return mixed
42     */
43    public function getValue()
44    {
45        return $this->value;
46    }
47
48    /**
49     * Returns false.
50     *
51     * @return bool
52     */
53    public function isLast()
54    {
55        return false;
56    }
57
58    /**
59     * Returns string representation for token.
60     *
61     * @return string
62     */
63    public function __toString()
64    {
65        return sprintf('contains("%s")', $this->value);
66    }
67}
68