8000 Add scalar typehints/return types by chalasr · Pull Request #23262 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add scalar typehints/return types #23262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
* @return bool Returns `true` if the class has a single-column ID and
* `false` otherwise.
*/
public function isSingleId()
public function isSingleId(): bool
{
return $this->singleId;
}
Expand All @@ -93,7 +93,7 @@ public function isSingleId()
* @return bool Returns `true` if the class has a single-column integer ID
* and `false` otherwise.
*/
public function isIntId()
public function isIntId(): bool
{
return $this->intId;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public function getIdValue($object)
*
* @return string The name of the ID field
*/
public function getIdField()
public function getIdField(): string
{
return $this->idField;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public function __call($method, $arguments)
return call_user_func_array(array($this->listener, $method), $arguments);
}

public function getWrappedListener()
public function getWrappedListener(): ListenerInterface
{
return $this->listener;
}

public function getInfo()
public function getInfo(): array
{
if (null === $this->stub) {
$this->stub = self::$hasVarDumper ? new ClassStub(get_class($this->listener)) : get_class($this->listener);
Expand Down
63 changes: 14 additions & 49 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,7 @@ final class FirewallConfig
private $listeners;
private $switchUser;

/**
* @param string $name
* @param string $userChecker
* @param string|null $requestMatcher
* @param bool $securityEnabled
* @param bool $stateless
* @param string|null $provider
* @param string|null $context
* @param string|null $entryPoint
* @param string|null $accessDeniedHandler
* @param string|null $accessDeniedUrl
* @param string[] $listeners
* @param array|null $switchUser
*/
public function __construct($name, $userChecker, $requestMatcher = null, $securityEnabled = true, $stateless = false, $provider = null, $context = null, $entryPoint = null, $accessDeniedHandler = null, $accessDeniedUrl = null, $listeners = array(), $switchUser = null)
public function __construct(string $name, string $userChecker, string $requestMatcher = null, bool $securityEnabled = true, bool $stateless = false, string $provider = null, string $context = null, string $entryPoint = null, string $accessDeniedHandler = null, string $accessDeniedUrl = null, array $listeners = array(), $switchUser = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason w 106D2 ill be displayed to describe this comment to others. Learn more.

Short array syntax for $listeners default value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed #12456 so think the consensus is to keep old style syntax, unless opinions have changed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line became very long and hard to read. Please split into multiple lines

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Please reconsider #18890 ! With scalar type hints and return types, it should be.

{
$this->name = $name;
$this->userChecker = $userChecker;
Expand All @@ -59,7 +45,7 @@ public function __construct($name, $userChecker, $requestMatcher = null, $securi
$this->switchUser = $switchUser;
}

public function getName()
public function getName(): string
{
return $this->name;
}
Expand All @@ -68,86 +54,65 @@ public function getName()
* @return string|null The request matcher service id or null if neither the request matcher, pattern or host
* options were provided
*/
public function getRequestMatcher()
public function getRequestMatcher(): ?string
{
return $this->requestMatcher;
}

public function isSecurityEnabled()
public function isSecurityEnabled(): bool
{
return $this->securityEnabled;
}

public function allowsAnonymous()
public function allowsAnonymous(): bool
{
return in_array('anonymous', $this->listeners, true);
}

public function isStateless()
public function isStateless(): bool
{
return $this->stateless;
}

/**
* @return string|null The provider service id
*/
public function getProvider()
public function getProvider(): ?string
{
return $this->provider;
}

/**
* @return string|null The context key (will be null if the firewall is stateless)
*/
public function getContext()
public function getContext(): ?string
{
return $this->context;
}

/**
* @return string|null The entry_point service id if configured, null otherwise
*/
public function getEntryPoint()
public function getEntryPoint(): ?string
{
return $this->entryPoint;
}

/**
* @return string The user_checker service id
*/
public function getUserChecker()
public function getUserChecker(): string
{
return $this->userChecker;
}

/**
* @return string|null The access_denied_handler service id if configured, null otherwise
*/
public function getAccessDeniedHandler()
public function getAccessDeniedHandler(): ?string
{
return $this->accessDeniedHandler;
}

/**
* @return string|null The access_denied_handler URL if configured, null otherwise
*/
public function getAccessDeniedUrl()
public function getAccessDeniedUrl(): ?string
{
return $this->accessDeniedUrl;
}

/**
* @return string[] An array of listener keys
*/
public function getListeners()
public function getListeners(): array
{
return $this->listeners;
}

/**
* @return array|null The switch_user parameters if configured, null otherwise
*/
public function getSwitchUser()
public function getSwitchUser(): ?array
{
return $this->switchUser;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;

Expand Down Expand Up @@ -63,7 +62,7 @@ public function testGetListeners()

$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();

$firewallConfig = new FirewallConfig('main', $this->getMockBuilder(UserCheckerInterface::class)->getMock());
$firewallConfig = new FirewallConfig('main', 'user_checker');
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);

$listener = $this->getMockBuilder(ListenerInterface::class)->getMock();
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Config/Loader/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getLocator()
* @throws FileLoaderImportCircularReferenceException
* @throws FileLocatorFileNotFoundException
*/
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
public function import($resource, $type = null, bool $ignoreErrors = false, $sourceResource = null)
{
if (is_string($resource) && strlen($resource) !== $i = strcspn($resource, '*?{[')) {
$ret = array();
Expand All @@ -104,7 +104,7 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
/**
* @internal
*/
protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors = false)
protected function glob(string $pattern, bool $recursive, &$resource = null, bool $ignoreErrors = false)
{
if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
$prefix = $pattern;
Expand Down Expand Up @@ -138,7 +138,7 @@ protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors =
}
}

private function doImport($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
private function doImport($resource, $type = null, bool $ignoreErrors = false, $sourceResource = null)
{
try {
$loader = $this->resolve($resource, $type);
Expand Down
39 changes: 7 additions & 32 deletions src/Symfony/Component/Console/Event/ConsoleErrorEvent.php
O E377 riginal file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Event;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -26,57 +25,33 @@ final class ConsoleErrorEvent extends ConsoleEvent
private $error;
private $exitCode;

public function __construct(InputInterface $input, OutputInterface $output, $error, Command $command = null)
public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null)
{
parent::__construct($command, $input, $output);

$this->setError($error);
$this->error = $error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be kept as is, BC break otherwise, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure as the class is final, do I miss it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right!

}

/**
* Returns the thrown error/exception.
*
* @return \Throwable
*/
public function getError()
public function getError(): \Throwable
{
return $this->error;
}

/**
* Replaces the thrown error/exception.
*
* @param \Throwable $error
*/
public function setError($error)
public function setError(\Throwable $error): void
{
if (!$error instanceof \Throwable && !$error instanceof \Exception) {
throw new InvalidArgumentException(sprintf('The error passed to ConsoleErrorEvent must be an instance of \Throwable or \Exception, "%s" was passed instead.', is_object($error) ? get_class($error) : gettype($error)));
}

$this->error = $error;
}

/**
* Sets the exit code.
*
* @param int $exitCode The command exit code
*/
public function setExitCode($exitCode)
public function setExitCode(int $exitCode): void
{
$this->exitCode = (int) $exitCode;
$this->exitCode = $exitCode;

$r = new \ReflectionProperty($this->error, 'code');
$r->setAccessible(true);
$r->setValue($this->error, $this->exitCode);
}

/**
* Gets the exit code.
*
* @return int The command exit code
*/
public function getExitCode()
public function getExitCode(): int
{
return null !== $this->exitCode ? $this->exitCode : ($this->error->getCode() ?: 1);
}
Expand Down
Loading
0