Code Duplication    Length = 20-20 lines in 2 locations

src/Assert.php 2 locations

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