Code Duplication    Length = 20-20 lines in 2 locations

src/Assert.php 2 locations

@@ 1168-1187 (lines=20) @@
1165
     * @return Assert
1166
     * @throws AssertionFailedException
1167
     */
1168
    public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8')
1169
    {
1170
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1171
        {
1172
            return $this;
1173
        }
1174
        $this->string($message, $propertyPath);
1175
        if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 )
1176
        {
1177
            $message = $message ?: $this->overrideError;
1178
            $message     = sprintf(
1179
                $message ?: 'Value "%s" does not start with "%s".',
1180
                $this->stringify($this->value),
1181
                $this->stringify($needle)
1182
            );
1183
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1184
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints);
1185
        }
1186
        return $this;
1187
    }
1188
1189
    /**
1190
     * Assert that string ends with a sequence of chars.
@@ 1231-1250 (lines=20) @@
1228
     * @return Assert
1229
     * @throws AssertionFailedException
1230
     */
1231
    public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8')
1232
    {
1233
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1234
        {
1235
            return $this;
1236
        }
1237
        $this->string($message, $propertyPath);
1238
        if ( mb_strpos($this->value, $needle, null, $encoding) === false )
1239
        {
1240
            $message = $message ?: $this->overrideError;
1241
            $message     = sprintf(
1242
                $message ?: 'Value "%s" does not contain "%s".',
1243
                $this->stringify($this->value),
1244
                $this->stringify($needle)
1245
            );
1246
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1247
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints);
1248
        }
1249
        return $this;
1250
    }
1251
1252
    /**
1253
     * Assert that value is in array of choices.