Skip to content

Commit

Permalink
minor #33056 cleanup remaining param $options and internal Intl FullT…
Browse files Browse the repository at this point in the history
…ransformer (Tobion)

This PR was merged into the 4.4 branch.

Discussion
----------

cleanup remaining param $options and internal Intl FullTransformer

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |#...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        |

Continuation of #33020 and #33019

Commits
-------

5dbcdc6 cleanup remaining param  and internal Intl FulLTransformer
  • Loading branch information
nicolas-grekas committed Aug 8, 2019
2 parents f91fa10 + 5dbcdc6 commit e0ccbf6
Show file tree
Hide file tree
Showing 29 changed files with 27 additions and 123 deletions.
Expand Up @@ -132,7 +132,6 @@ abstract protected function describeContainerTags(ContainerBuilder $builder, arr
* * name: name of described service
*
* @param Definition|Alias|object $service
* @param array $options
*/
abstract protected function describeContainerService($service, array $options = [], ContainerBuilder $builder = null);

Expand Down Expand Up @@ -176,7 +175,6 @@ abstract protected function describeEventDispatcherListeners(EventDispatcherInte
* Describes a callable.
*
* @param callable $callable
* @param array $options
*/
abstract protected function describeCallable($callable, array $options = []);

Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
Expand Up @@ -37,7 +37,6 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI

/**
* @param mixed $resource The main resource to load
* @param array $options An array of options
*/
public function __construct(ContainerInterface $container, $resource, array $options = [], RequestContext $context = null, ContainerInterface $parameters = null, LoggerInterface $logger = null, string $defaultLocale = null)
{
Expand Down
Expand Up @@ -36,8 +36,7 @@ public function __construct(FragmentHandler $handler)
/**
* Returns the fragment content for a given URI.
*
* @param string $uri A URI
* @param array $options An array of options
* @param string $uri
*
* @return string The fragment content
*
Expand Down
4 changes: 0 additions & 4 deletions src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
Expand Up @@ -65,10 +65,6 @@ class Translator extends BaseTranslator implements WarmableInterface
* * debug: Whether to enable debugging or not (false by default)
* * resource_files: List of translation resources available grouped by locale.
*
* @param string $defaultLocale
* @param array $loaderIds An array of loader Ids
* @param array $options An array of options
*
* @throws InvalidArgumentException
*/
public function __construct(ContainerInterface $container, MessageFormatterInterface $formatter, string $defaultLocale, array $loaderIds = [], array $options = [])
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/Cache/Traits/MemcachedTrait.php
Expand Up @@ -71,7 +71,6 @@ private function init(\Memcached $client, string $namespace, int $defaultLifetim
* - [['localhost', 11211, 33]]
*
* @param array[]|string|string[] $servers An array of servers, a DSN, or an array of DSNs
* @param array $options An array of options
*
* @return \Memcached
*
Expand Down
Expand Up @@ -24,7 +24,6 @@ interface DescriptorInterface
* Describes an object if supported.
*
* @param object $object
* @param array $options
*/
public function describe(OutputInterface $output, $object, array $options = []);
}
Expand Up @@ -61,7 +61,6 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
*
* @param string|null $foreground The style foreground color name
* @param string|null $background The style background color name
* @param array $options The style options
*/
public function __construct(string $foreground = null, string $background = null, array $options = [])
{
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/Console/Helper/DescriptorHelper.php
Expand Up @@ -49,7 +49,6 @@ public function __construct()
* * raw_text: boolean, sets output type as raw
*
* @param object $object
* @param array $options
*
* @throws InvalidArgumentException when the given format is not supported
*/
Expand Down
Expand Up @@ -21,8 +21,6 @@ interface DumperInterface
/**
* Dumps the service container.
*
* @param array $options An array of options
*
* @return string The representation of the service container
*/
public function dump(array $options = []);
Expand Down
Expand Up @@ -32,8 +32,6 @@ class ResizeFormListener implements EventSubscriberInterface
private $deleteEmpty;

/**
* @param string $type
* @param array $options
* @param bool $allowAdd Whether children could be added to the group
* @param bool $allowDelete Whether children could be removed from the group
* @param bool|callable $deleteEmpty
Expand Down
32 changes: 7 additions & 25 deletions src/Symfony/Component/Form/Tests/AbstractFormTest.php
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormInterface;

abstract class AbstractFormTest extends TestCase
{
Expand All @@ -30,7 +31,7 @@ abstract class AbstractFormTest extends TestCase
protected $factory;

/**
* @var \Symfony\Component\Form\FormInterface
* @var FormInterface
*/
protected $form;

Expand All @@ -48,43 +49,24 @@ protected function tearDown(): void
$this->form = null;
}

/**
* @return \Symfony\Component\Form\FormInterface
*/
abstract protected function createForm();
abstract protected function createForm(): FormInterface;

/**
* @param string $name
* @param string|null $dataClass
* @param array $options
*
* @return FormBuilder
*/
protected function getBuilder($name = 'name', EventDispatcherInterface $dispatcher = null, $dataClass = null, array $options = [])
protected function getBuilder(?string $name = 'name', EventDispatcherInterface $dispatcher = null, string $dataClass = null, array $options = []): FormBuilder
{
return new FormBuilder($name, $dataClass, $dispatcher ?: $this->dispatcher, $this->factory, $options);
}

/**
* @return MockObject
*/
protected function getDataMapper()
protected function getDataMapper(): MockObject
{
return $this->getMockBuilder('Symfony\Component\Form\DataMapperInterface')->getMock();
}

/**
* @return MockObject
*/
protected function getDataTransformer()
protected function getDataTransformer(): MockObject
{
return $this->getMockBuilder('Symfony\Component\Form\DataTransformerInterface')->getMock();
}

/**
* @return MockObject
*/
protected function getFormValidator()
protected function getFormValidator(): MockObject
{
return $this->getMockBuilder('Symfony\Component\Form\FormValidatorInterface')->getMock();
}
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Form/Tests/CompoundFormTest.php
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\SubmitButtonBuilder;
Expand Down Expand Up @@ -190,7 +191,7 @@ public function testAddUsingNameAndType()

public function testAddUsingIntegerNameAndType()
{
$child = $this->getBuilder(0)->getForm();
$child = $this->getBuilder('0')->getForm();

$this->factory->expects($this->once())
->method('createNamed')
Expand Down Expand Up @@ -1123,7 +1124,7 @@ public function testFileUpload()
$this->assertNull($this->form->get('bar')->getData());
}

protected function createForm($name = 'name', $compound = true)
protected function createForm(string $name = 'name', bool $compound = true): FormInterface
{
$builder = $this->getBuilder($name);

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Form/Tests/SimpleFormTest.php
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Tests\Fixtures\FixedDataTransformer;
use Symfony\Component\Form\Tests\Fixtures\FixedFilterListener;
use Symfony\Component\PropertyAccess\PropertyPath;
Expand Down Expand Up @@ -1096,7 +1097,7 @@ public function testCannotCallGetViewDataInPreSetDataListener()
$form->setData('foo');
}

protected function createForm()
protected function createForm(): FormInterface
{
return $this->getBuilder()->getForm();
}
Expand Down
Expand Up @@ -41,7 +41,6 @@ class MemcachedSessionHandler extends AbstractSessionHandler
* * expiretime: The time to live in seconds.
*
* @param \Memcached $memcached A \Memcached instance
* @param array $options An associative array of Memcached options
*
* @throws \InvalidArgumentException When unsupported options are passed
*/
Expand Down
Expand Up @@ -61,9 +61,6 @@ class MongoDbSessionHandler extends AbstractSessionHandler
* If you use such an index, you can drop `gc_probability` to 0 since
* no garbage-collection is required.
*
* @param \MongoDB\Client $mongo A MongoDB\Client instance
* @param array $options An associative array of field options
*
* @throws \InvalidArgumentException When "database" or "collection" not provided
*/
public function __construct(\MongoDB\Client $mongo, array $options)
Expand Down
Expand Up @@ -165,7 +165,6 @@ class PdoSessionHandler extends AbstractSessionHandler
* * lock_mode: The strategy for locking, see constants [default: LOCK_TRANSACTIONAL]
*
* @param \PDO|string|null $pdoOrDsn A \PDO instance or DSN string or URL string or null
* @param array $options An associative array of options
*
* @throws \InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
*/
Expand Down
Expand Up @@ -35,7 +35,6 @@ class RedisSessionHandler extends AbstractSessionHandler
* * prefix: The prefix to use for the keys in order to avoid collision on the Redis server.
*
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client|RedisProxy $redis
* @param array $options An associative array of options
*
* @throws \InvalidArgumentException When unsupported client or options are passed
*/
Expand Down
Expand Up @@ -97,7 +97,6 @@ class NativeSessionStorage implements SessionStorageInterface
* trans_sid_hosts, $_SERVER['HTTP_HOST']
* trans_sid_tags, "a=href,area=href,frame=src,form="
*
* @param array $options Session configuration options
* @param \SessionHandlerInterface|null $handler
*/
public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null)
Expand Down
Expand Up @@ -62,7 +62,6 @@ public function addRenderer(FragmentRendererInterface $renderer)
*
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* @param string $renderer The renderer name
* @param array $options An array of options
*
* @return string|null The Response content or null when the Response is streamed
*
Expand Down
Expand Up @@ -25,8 +25,7 @@ interface FragmentRendererInterface
/**
* Renders a URI and returns the Response content.
*
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* @param array $options An array of options
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
*
* @return Response A Response instance
*/
Expand Down
Expand Up @@ -69,21 +69,9 @@ public function __construct(string $pattern, string $timezone)
];
}

/**
* Return the array of Transformer objects.
*
* @return Transformer[] Associative array of Transformer objects (format char => Transformer)
*/
public function getTransformers()
{
return $this->transformers;
}

/**
* Format a DateTime using ICU dateformat pattern.
*
* @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
*
* @return string The formatted value
*/
public function format(\DateTime $dateTime)
Expand All @@ -98,14 +86,9 @@ public function format(\DateTime $dateTime)
/**
* Return the formatted ICU value for the matched date characters.
*
* @param string $dateChars The date characters to be replaced with a formatted ICU value
* @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
*
* @return string The formatted value
*
* @throws NotImplementedException When it encounters a not implemented date character
*/
public function formatReplace($dateChars, $dateTime)
private function formatReplace(string $dateChars, \DateTime $dateTime): string
{
$length = \strlen($dateChars);

Expand Down Expand Up @@ -167,12 +150,10 @@ public function parse(\DateTime $dateTime, $value)
/**
* Retrieve a regular expression to match with a formatted value.
*
* @param string $pattern The pattern to create the reverse matching regular expression
*
* @return string The reverse matching regular expression with named captures being formed by the
* transformer index in the $transformer array
*/
public function getReverseMatchingRegExp($pattern)
private function getReverseMatchingRegExp(string $pattern): string
{
$escapedPattern = preg_quote($pattern, '/');

Expand All @@ -189,9 +170,8 @@ public function getReverseMatchingRegExp($pattern)
return $this->replaceQuoteMatch($dateChars);
}

$transformers = $this->getTransformers();
if (isset($transformers[$transformerIndex])) {
$transformer = $transformers[$transformerIndex];
if (isset($this->transformers[$transformerIndex])) {
$transformer = $this->transformers[$transformerIndex];
$captureName = str_repeat($transformerIndex, $length);

return "(?P<$captureName>".$transformer->getReverseMatchingRegExp($length).')';
Expand All @@ -203,24 +183,16 @@ public function getReverseMatchingRegExp($pattern)

/**
* Check if the first char of a string is a single quote.
*
* @param string $quoteMatch The string to check
*
* @return bool true if matches, false otherwise
*/
public function isQuoteMatch($quoteMatch)
private function isQuoteMatch(string $quoteMatch): bool
{
return "'" === $quoteMatch[0];
}

/**
* Replaces single quotes at the start or end of a string with two single quotes.
*
* @param string $quoteMatch The string to replace the quotes
*
* @return string A string with the single quotes replaced
*/
public function replaceQuoteMatch($quoteMatch)
private function replaceQuoteMatch(string $quoteMatch): string
{
if (preg_match("/^'+$/", $quoteMatch)) {
return str_replace("''", "'", $quoteMatch);
Expand All @@ -231,12 +203,8 @@ public function replaceQuoteMatch($quoteMatch)

/**
* Builds a chars match regular expression.
*
* @param string $specialChars A string of chars to build the regular expression
*
* @return string The chars match regular expression
*/
protected function buildCharsMatch($specialChars)
private function buildCharsMatch(string $specialChars): string
{
$specialCharsArray = str_split($specialChars);

Expand All @@ -250,10 +218,8 @@ protected function buildCharsMatch($specialChars)
/**
* Normalize a preg_replace match array, removing the numeric keys and returning an associative array
* with the value and pattern values for the matched Transformer.
*
* @return array
*/
protected function normalizeArray(array $data)
private function normalizeArray(array $data): array
{
$ret = [];

Expand All @@ -275,12 +241,9 @@ protected function normalizeArray(array $data)
* Calculates the Unix timestamp based on the matched values by the reverse matching regular
* expression of parse().
*
* @param \DateTime $dateTime The DateTime object to be used to calculate the timestamp
* @param array $options An array with the matched values to be used to calculate the timestamp
*
* @return bool|int The calculated timestamp or false if matched date is invalid
*/
protected function calculateUnixTimestamp(\DateTime $dateTime, array $options)
private function calculateUnixTimestamp(\DateTime $dateTime, array $options)
{
$options = $this->getDefaultValueForOptions($options);

Expand Down

0 comments on commit e0ccbf6

Please sign in to comment.