8000 [BugFix][Console] Fix type hints of OutputFormatter in Output constructors by canni · Pull Request #2911 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[BugFix][Console] Fix type hints of OutputFormatter in Output constructors #2911

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

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Output/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Console\Output;

use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;

/**
* ConsoleOutput is the default class for all CLI output. It uses STDOUT.
Expand Down Expand Up @@ -40,7 +40,7 @@ class ConsoleOutput extends StreamOutput
*
* @api
*/
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatter $formatter = null)
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
{
parent::__construct(fopen('php://stdout', 'w'), $verbosity, $decorated, $formatter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Output/StreamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Console\Output;

use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;

/**
* StreamOutput writes the output to a given stream.
Expand Down Expand Up @@ -45,7 +45,7 @@ class StreamOutput extends Output
*
* @api
*/
public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatter $formatter = null)
public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
{
if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected function filterResponse($response)
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
$headers['Set-Cookie'] = implode(', ', $cookies);
$headers['Set-Cookie'] = $cookies;
}

return new DomResponse($response->getContent(), $response->getStatusCode(), $headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ public function format(\DateTime $dateTime, $length)
*/
public function getReverseMatchingRegExp($length)
{
if (1 == $length) {
$regExp = '\d{1,2}';
} else {
$regExp = '\d{'.$length.'}';
}

return $regExp;
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ public function formatReplace($dateChars, $dateTime)
$transformer = $this->transformers[$dateChars[0]];

return $transformer->format($dateTime, $length);
} else {
// handle unimplemented characters
if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
throw new NotImplementedException(sprintf("Unimplemented date character '%s' in format '%s'", $dateChars[0], $this->pattern));
}
}

// handle unimplemented characters
if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
throw new NotImplementedException(sprintf("Unimplemented date character '%s' in format '%s'", $dateChars[0], $this->pattern));
}
}

Expand Down Expand Up @@ -181,7 +181,6 @@ public function getReverseMatchingRegExp($pattern)
}

$transformers = $that->getTransformers();

if (isset($transformers[$transformerIndex])) {
$transformer = $transformers[$transformerIndex];
$captureName = str_repeat($transformerIndex, $length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Hour1200Transformer extends HourTransformer
public function format(\DateTime $dateTime, $length)
{
$hourOfDay = $dateTime->format('g');
$hourOfDay = ('12' == $hourOfDay) ? '0' : $hourOfDay;
$hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay;

return $this->padLeft($hourOfDay, $length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function normalizeHour($hour, $marker = null)
$hour = 0;
} elseif ('PM' === $marker && 12 !== $hour) {
// If PM and hour is not 12 (1-12), sum 12 hour
$hour = $hour + 12;
$hour += 12;
}

return $hour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public function format(\DateTime $dateTime, $length)
*/
public function normalizeHour($hour, $marker = null)
{
if (null === $marker && 24 === $hour) {
$hour = 0;
} else if ('AM' == $marker) {
if ((null === $marker && 24 === $hour) || 'AM' == $marker) {
$hour = 0;
} else if ('PM' == $marker) {
$hour = 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ public function format(\DateTime $dateTime, $length)
*/
public function getReverseMatchingRegExp($length)
{
if (1 == $length) {
$regExp = '\d{1,2}';
} else {
$regExp = '\d{'.$length.'}';
}

return $regExp;
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
}

/**
Expand Down
31 changes: 15 additions & 16 deletions src/Symfony/Component/Locale/Stub/DateFormat/MonthTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MonthTransformer extends Transformer
*/
public function __construct()
{
if (0 == count(self::$shortMonths)) {
if (0 === count(self::$shortMonths)) {
self::$shortMonths = array_map(function($month) {
return substr($month, 0, 3);
}, self::$months);
Expand All @@ -76,19 +76,21 @@ public function __construct()
public function format(\DateTime $dateTime, $length)
{
$matchLengthMap = array(
1 => 'n',
2 => 'm',
3 => 'M',
4 => 'F',
1 => 'n',
2 => 'm',
3 => 'M',
4 => 'F',
);

if (isset($matchLengthMap[$length])) {
return $dateTime->format($matchLengthMap[$length]);
} else if (5 == $length) {
return $dateTime->format($matchLengthMap[$length]);
}

if (5 === $length) {
return substr($dateTime->format('M'), 0, 1);
} else {
return $this->padLeft($dateTime->format('m'), $length);
}

return $this->padLeft($dateTime->format('m'), $length);
}

/**
Expand Down Expand Up @@ -123,18 +125,15 @@ public function getReverseMatchingRegExp($length)
public function extractDateOptions($matched, $length)
{
if (!is_numeric($matched)) {
if (3 == $length) {
if (3 === $length) {
$matched = self::$flippedShortMonths[$matched] + 1;
}
elseif (4 == $length) {
} elseif (4 === $length) {
$matched = self::$flippedMonths[$matched] + 1;
}
elseif (5 == $length) {
} elseif (5 === $length) {
// IntlDateFormatter::parse() always returns false for MMMMM or LLLLL
$matched = false;
}
}
else {
} else {
$matched = (int) $matched;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ public function format(\DateTime $dateTime, $length)
*/
public function getReverseMatchingRegExp($length)
{
if (1 == $length) {
$regExp = '\d{1,2}';
} else {
$regExp = '\d{'.$length.'}';
}

return $regExp;
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
}

/**
Expand Down
14 changes: 4 additions & 10 deletions src/Symfony/Component/Locale/Stub/DateFormat/YearTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,19 @@ class YearTransformer extends Transformer
*/
public function format(\DateTime $dateTime, $length)
{
if (2 == $length) {
if (2 === $length) {
return $dateTime->format('y');
} else {
return $this->padLeft($dateTime->format('Y'), $length);
}

return $this->padLeft($dateTime->format('Y'), $length);
}

/**
* {@inheritDoc}
*/
public function getReverseMatchingRegExp($length)
{
if (2 == $length) {
$regExp = '\d{2}';
} else {
$regExp = '\d{4}';
}

return $regExp;
return 2 === $length ? '\d{2}' : '\d{4}';
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Locale/Stub/StubIntl.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract class StubIntl
*/
static public function isFailure($errorCode)
{
return in_array($errorCode, static::$errorCodes, true)
return in_array($errorCode, self::$errorCodes, true)
&& $errorCode !== self::U_ZERO_ERROR;
}

Expand All @@ -90,7 +90,7 @@ static public function isFailure($errorCode)
*/
static public function getErrorCode()
{
return static::$errorCode;
return self::$errorCode;
}

/**
Expand All @@ -102,7 +102,7 @@ static public function getErrorCode()
*/
static public function getErrorMessage()
{
return static::$errorMessages[static::$errorCode];
return self::$errorMessages[self::$errorCode];
}

/**
Expand All @@ -114,10 +114,10 @@ static public function getErrorMessage()
*/
static public function setErrorCode($code)
{
if (!isset(static::$errorMessages[$code])) {
if (!isset(self::$errorMessages[$code])) {
throw new \InvalidArgumentException(sprintf('No such error code: "%s"', $code));
}

static::$errorCode = $code;
self::$errorCode = $code;
}
}
3 changes: 1 addition & 2 deletions src/Symfony/Component/Locale/Stub/StubLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ static public function setDefault($locale)
static private function getStubData($locale, $cacheVariable, $stubDataDir)
{
if ('en' != $locale) {
$message = 'Only the \'en\' locale is supported. '.NotImplementedException::INTL_INSTALL_MESSAGE;
throw new \InvalidArgumentException($message);
throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE));
}

if (empty(self::${$cacheVariable})) {
Expand Down
10 changes: 8 additions & 2 deletions tests/Symfony/Tests/Component/HttpKernel/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,22 @@ public function testFilterResponseConvertsCookies()
$m = $r->getMethod('filterResponse');
$m->setAccessible(true);

$expected = array(
'foo=bar; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly',
'foo1=bar1; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly'
);

$response = new Response();
$response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$domResponse = $m->invoke($client, $response);
$this->assertEquals('foo=bar; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly', $domResponse->getHeader('Set-Cookie'));
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));

$response = new Response();
$response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$response->headers->setCookie(new Cookie('foo1', 'bar1', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
$domResponse = $m->invoke($client, $response);
$this->assertEquals('foo=bar; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly, foo1=bar1; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly', $domResponse->getHeader('Set-Cookie'));
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
$this->assertEquals($expected, $domResponse->getHeader('Set-Cookie', false));
}

public function testUploadedFile()
Expand Down
0