Code Duplication    Length = 20-20 lines in 2 locations

src/Assert.php 2 locations

@@ 1143-1162 (lines=20) @@
1140
     * @return Assert
1141
     * @throws AssertionFailedException
1142
     */
1143
    public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8')
1144
    {
1145
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1146
        {
1147
            return $this;
1148
        }
1149
        $this->string($message, $propertyPath);
1150
        if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 )
1151
        {
1152
            $message = $message ?: $this->overrideError;
1153
            $message     = sprintf(
1154
                $message ?: 'Value "%s" does not start with "%s".',
1155
                $this->stringify($this->value),
1156
                $this->stringify($needle)
1157
            );
1158
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1159
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints);
1160
        }
1161
        return $this;
1162
    }
1163
1164
    /**
1165
     * Assert that string ends with a sequence of chars.
@@ 1206-1225 (lines=20) @@
1203
     * @return Assert
1204
     * @throws AssertionFailedException
1205
     */
1206
    public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8')
1207
    {
1208
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1209
        {
1210
            return $this;
1211
        }
1212
        $this->string($message, $propertyPath);
1213
        if ( mb_strpos($this->value, $needle, null, $encoding) === false )
1214
        {
1215
            $message = $message ?: $this->overrideError;
1216
            $message     = sprintf(
1217
                $message ?: 'Value "%s" does not contain "%s".',
1218
                $this->stringify($this->value),
1219
                $this->stringify($needle)
1220
            );
1221
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1222
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints);
1223
        }
1224
        return $this;
1225
    }
1226
1227
    /**
1228
     * Assert that value is in array of choices.