8000 minor #12841 [3.0] Removed all $that variables (saro0h) · symfony/symfony@ad8289b · GitHub
[go: up one dir, main page]

Skip to content

Commit ad8289b

Browse files
committed
minor #12841 [3.0] Removed all $that variables (saro0h)
This PR was merged into the 3.0-dev branch. Discussion ---------- [3.0] Removed all $that variables | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Commits ------- 7b33d1a Removed all $that variables
2 parents 4c1ab52 + 7b33d1a commit ad8289b

File tree

39 files changed

+497
-671
lines changed

39 files changed

+497
-671
lines changed

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
6363
$choiceListCache = & $this->choiceListCache;
6464
$registry = $this->registry;
6565
$propertyAccessor = $this->propertyAccessor;
66-
$type = $this;
6766

68-
$loader = function (Options $options) use ($type) {
67+
$loader = function (Options $options) {
6968
if (null !== $options['query_builder']) {
70-
return $type->getLoader($options['em'], $options['query_builder'], $options['class']);
69+
return $this->getLoader($options['em'], $options['query_builder'], $options['class']);
7170
}
7271
};
7372

src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ public function getProxyFactoryCode(Definition $definition, $id)
7171

7272
return <<<EOF
7373
if (\$lazyLoad) {
74-
\$container = \$this;
7574
7675
$instantiation new $proxyClass(
77-
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) use (\$container) {
78-
\$wrappedInstance = \$container->$methodName(false);
76+
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) {
77+
\$wrappedInstance = \$this->$methodName(false);
7978
8079
\$proxy->setProxyInitializer(null);
8180

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ public function __construct()
4646
public function getFooService($lazyLoad = true)
4747
{
4848
if ($lazyLoad) {
49-
$container = $this;
5049

5150
return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8(
52-
function (& $wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {
53-
$wrappedInstance = $container->getFooService(false);
51+
function (& $wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
52+
$wrappedInstance = $this->getFooService(false);
5453

5554
$proxy->setProxyInitializer(null);
5655

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ class ProjectServiceContainer extends Container
66
public function getFooService($lazyLoad = true)
77
{
88
if ($lazyLoad) {
9-
$container = $this;
109

1110
return $this->services['foo'] = new stdClass_%s(
12-
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {
13-
$wrappedInstance = $container->getFooService(false);
11+
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
12+
$wrappedInstance = $this->getFooService(false);
1413

1514
$proxy->setProxyInitializer(null);
1615

@@ -24,4 +23,4 @@ class ProjectServiceContainer extends Container
2423
}
2524

2625
class stdClass_%s extends \stdClass implements \ProxyManager\Proxy\VirtualProxyInterface
27-
{%a}%A
26+
{%a}%A

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public function testGetProxyFactoryCode()
7171
$code = $this->dumper->getProxyFactoryCode($definition, 'foo');
7272

7373
$this->assertStringMatchesFormat(
74-
'%wif ($lazyLoad) {%w$container = $this;%wreturn $this->services[\'foo\'] = new '
74+
'%wif ($lazyLoad) {%wreturn $this->services[\'foo\'] = new '
7575
.'SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest_%s(%wfunction '
76-
.'(&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {'
77-
.'%w$wrappedInstance = $container->getFooService(false);%w$proxy->setProxyInitializer(null);'
76+
.'(&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {'
77+
.'%w$wrappedInstance = $this->getFooService(false);%w$proxy->setProxyInitializer(null);'
7878
.'%wreturn true;%w}%w);%w}%w',
7979
$code
8080
);

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,8 @@ public function getFileLink($file, $line)
205205

206206
public function formatFileFromText($text)
207207
{
208-
$that = $this;
209-
210-
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) use ($that) {
211-
return 'in '.$that->formatFile($match[2], $match[3]);
208+
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
209+
return 'in '.$this->formatFile($match[2], $match[3]);
212210
}, $text);
213211
}
214212

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ public function getFileLink($file, $line)
197197

198198
public function formatFileFromText($text)
199199
{
200-
$that = $this;
201-
202-
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) use ($that) {
203-
return 'in '.$that->formatFile($match[2], $match[3]);
200+
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
201+
return 'in '.$this->formatFile($match[2], $match[3]);
204202
}, $text);
205203
}
206204

src/Symfony/Bundle/FrameworkBundle/Translation/PhpStringTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static function parseEscapeSequences($str, $quote)
106106
);
107107
}
108108

109-
public static function parseCallback($matches)
109+
private static function parseCallback($matches)
110110
{
111111
$str = $matches[1];
112112

src/Symfony/Bundle/TwigBundle/Tests/Controller/PreviewErrorControllerTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class PreviewErrorControllerTest extends TestCase
2121
{
2222
public function testForwardRequestToConfiguredController()
2323
{
24-
$self = $this;
25-
2624
$request = Request::create('whatever');
2725
$response = new Response("");
2826
$code = 123;
@@ -33,15 +31,14 @@ public function testForwardRequestToConfiguredController()
3331
->expects($this->once())
3432
->method('handle')
3533
->with(
36-
$this->callback(function (Request $request) use ($self, $logicalControllerName, $code) {
34+
$this->callback(function (Request $request) use ($logicalControllerName, $code) {
3735

38-
$self->assertEquals($logicalControllerName, $request->attributes->get('_controller'));
36+
$this->assertEquals($logicalControllerName, $request->attributes->get('_controller'));
3937

4038
$exception = $request->attributes->get('exception');
41-
$self->assertInstanceOf('Symfony\Component\Debug\Exception\FlattenException', $exception);
42-
$self->assertEquals($code, $exception->getStatusCode());
43-
44-
$self->assertFalse($request->attributes->get('showException'));
39+
$this->assertInstanceOf('Symfony\Component\HttpKernel\Exception\FlattenException', $exception);
40+
$this->assertEquals($code, $exception->getStatusCode());
41+
$this->assertFalse($request->attributes->get('showException'));
4542

4643
return true;
4744
}),

src/Symfony/Component/Console/Helper/DialogHelper.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,8 @@ public function askHiddenResponse(OutputInterface $output, $question, $fallback
346346
*/
347347
public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null, array $autocomplete = null)
348348
{
349-
$that = $this;
350-
351-
$interviewer = function () use ($output, $question, $default, $autocomplete, $that) {
352-
return $that->ask($output, $question, $default, $autocomplete);
349+
$interviewer = function () use ($output, $question, $default, $autocomplete) {
350+
return $this->ask($output, $question, $default, $autocomplete);
353351
};
354352

355353
return $this->validateAttempts($interviewer, $output, $validator, $attempts);
@@ -376,10 +374,8 @@ public function askAndValidate(OutputInterface $output, $question, $validator, $
376374
*/
377375
public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true)
378376
{
379-
$that = $this;
380-
381-
$interviewer = function () use ($output, $question, $fallback, $that) {
382-
return $that->askHiddenResponse($output, $question, $fallback);
377+
$interviewer = function () use ($output, $question, $fallback) {
378+
return $this->askHiddenResponse($output, $question, $fallback);
383379
};
384380

385381
return $this->validateAttempts($interviewer, $output, $validator, $attempts);

src/Symfony/Component/Console/Helper/ProcessHelper.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,16 @@ public function wrapCallback(OutputInterface $output, Process $process, $callbac
111111
{
112112
$formatter = $this->getHelperSet()->get('debug_formatter');
113113

114-
$that = $this;
115-
116-
return function ($type, $buffer) use ($output, $process, $callback, $formatter, $that) {
117-
$output->write($formatter->progress(spl_object_hash($process), $that->escapeString($buffer), Process::ERR === $type));
114+
return function ($type, $buffer) use ($output, $process, $callback, $formatter) {
115+
$output->write($formatter->progress(spl_object_hash($process), $this->escapeString($buffer), Process::ERR === $type));
118116

119117
if (null !== $callback) {
120118
call_user_func($callback, $type, $buffer);
121119
}
122120
};
123121
}
124122

125-
/**
126-
* This method is public for PHP 5.3 compatibility, it should be private.
127-
*
128-
* @internal
129-
*/
130-
public function escapeString($str)
123+
private function escapeString($str)
131124
{
132125
return str_replace('<', '\\<', $str);
133126
}

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ public function getProgress()
193193
/**
194194
* Gets the progress bar step width.
195195
*
196-
* @internal This method is public for PHP 5.3 compatibility, it should not be used.
197-
*
198-
* @return int The progress bar step width
196+
* @return int The progress bar step width
199197
*/
200-
public function getStepWidth()
198+
private function getStepWidth()
201199
{
202200
return $this->stepWidth;
203201
}
@@ -432,15 +430,11 @@ public function display()
432430
return;
433431
}
434432

435-
// these 3 variables can be removed in favor of using $this in the closure when support for PHP 5.3 will be dropped.
436-
$self = $this;
437-
$output = $this->output;
438-
$messages = $this->messages;
439-
$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self, $output, $messages) {
440-
if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
441-
$text = call_user_func($formatter, $self, $output);
442-
} elseif (isset($messages[$matches[1]])) {
443-
$text = $messages[$matches[1]];
433+
$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) {
434+
if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) {
435+
$text = call_user_func($formatter, $this, $this->output);
436+
} elseif (isset($this->messages[$matches[1]])) {
437+
$text = $this->messages[$matches[1]];
444438
} else {
445439
return $matches[0];
446440
}

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
4949
return $this->doAsk($output, $question);
5050
}
5151

52-
$that = $this;
53-
54-
$interviewer = function () use ($output, $question, $that) {
55-
return $that->doAsk($output, $question);
52+
$interviewer = function () use ($output, $question) {
53+
return $this->doAsk($output, $question);
5654
};
5755

5856
return $this->validateAttempts($interviewer, $output, $question);

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,13 @@ public function getParameterOption($values, $default = false)
333333
*/
334334
public function __toString()
335335
{
336-
$self = $this;
337-
$tokens = array_map(function ($token) use ($self) {
336+
$tokens = array_map(function ($token) {
338337
if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) {
339-
return $match[1].$self->escapeToken($match[2]);
338+
return $match[1].$this->escapeToken($match[2]);
340339
}
341340

342341
if ($token && $token[0] !== '-') {
343-
return $self->escapeToken($token);
342+
return $this->escapeToken($token);
344343
}
345344

346345
return $token;

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,30 @@ public function handle(\Exception $exception)
112112

113113
$caughtLength = $this->caughtLength = 0;
114114

115-
ob_start(array($this, 'catchOutput'));
115+
ob_start(function($buffer) {
116+
$this->caughtBuffer = $buffer;
117+
118+
return '';
119+
});
120+
121+
116122
$this->failSafeHandle($exception);
117123
while (null === $this->caughtBuffer && ob_end_flush()) {
118124
// Empty loop, everything is in the condition
119125
}
120126
if (isset($this->caughtBuffer[0])) {
121-
ob_start(array($this, 'cleanOutput'));
127+
ob_start(function($buffer) {
128+
if ($this->caughtLength) {
129+
// use substr_replace() instead of substr() for mbstring overloading resistance
130+
$cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength);
131+
if (isset($cleanBuffer[0])) {
132+
$buffer = $cleanBuffer;
133+
}
134+
}
135+
136+
return $buffer;
137+
});
138+
122139
echo $this->caughtBuffer;
123140
$caughtLength = ob_get_length();
124141
}
@@ -426,30 +443,4 @@ protected static function utf8Htmlize($str)
426443

427444
return htmlspecialchars($str, ENT_QUOTES | (PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), 'UTF-8');
428445
}
429-
430-
/**
431-
* @internal
432-
*/
433-
public function catchOutput($buffer)
434-
{
435-
$this->caughtBuffer = $buffer;
436-
437-
return '';
438-
}
439-
440-
/**
441-
* @internal
442-
*/
443-
public function cleanOutput($buffer)
444-
{
445-
if ($this->caughtLength) {
446-
// use substr_replace() instead of substr() for mbstring overloading resistance
447-
$cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength);
448-
if (isset($cleanBuffer[0])) {
449-
$buffer = $cleanBuffer;
450-
}
451-
}
452-
453-
return $buffer;
454-
}
455446
}

0 commit comments

Comments
 (0)
0