Skip to content

setPattern should accept string values #483

Open
@CrazyMuffin

Description

@CrazyMuffin

When I attempt to extend class and set my own pattern, application crashes because:

  1. When trying to set string, setPattern declines the value because of invalid typehint.
  2. When I set the string value into array, application crashes further down as values in Finder::names should be string only. (they are later passed into preg_match function).

Invalid typehint:

public function setPattern(array $pattern)
{
$this->pattern = $pattern;
}

Function call that expects string:

if ($this->pattern) {
$finder->name($this->pattern);
}

Function itself:
https://github.com/symfony/symfony/blob/9e82562948253bf547243aa1c4cf6ec734d608da/src/Symfony/Component/Finder/Finder.php#L150-L170

Solution:

  1. Change argument typehint to string
  2. Allow array, but iterate values on $finder::name call

Workaround:
Copy class but reimplement everything

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions