8000 Removed all $that variables · symfony/symfony@3743b76 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3743b76

Browse files
committed
Removed all $that variables
1 parent f4e7fd7 commit 3743b76

File tree

40 files changed

+476
-640
lines changed

40 files changed

+476
-640
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: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,20 +427,14 @@ protected static function utf8Htmlize($str)
427427
return htmlspecialchars($str, ENT_QUOTES | (PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), 'UTF-8');
428428
}
429429

430-
/**
431-
* @internal
432-
*/
433-
public function catchOutput($buffer)
430+
private function catchOutput($buffer)
434431
{
435432
$this->caughtBuffer = $buffer;
436433

437434
return '';
438435
}
439436

440-
/**
441-
* @internal
442-
*/
443-
public function cleanOutput($buffer)
437+
private function cleanOutput($buffer)
444438
{
445439
if ($this->caughtLength) {
446440
// use substr_replace() instead of substr() for mbstring overloading resistance

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,13 @@ public function testHandleError()
237237

238238
$logger = $this->getMock('Psr\Log\LoggerInterface');
239239

240-
$that = $this;
241-
$warnArgCheck = function ($logLevel, $message, $context) use ($that) {
242-
$that->assertEquals('info', $logLevel);
243-
$that->assertEquals('foo', $message);
244-
$that->assertArrayHasKey('type', $context);
245-
$that->assertEquals($context['type'], E_USER_DEPRECATED);
246-
$that->assertArrayHasKey('stack', $context);
247-
$that->assertInternalType('array', $context['stack']);
240+
$warnArgCheck = function ($logLevel, $message, $context) {
241+
$this->assertEquals('info', $logLevel);
242+
$this->assertEquals('foo', $message);
243+
$this->assertArrayHasKey('type', $context);
244+
$this->assertEquals($context['type'], E_USER_DEPRECATED);
245+
$this->assertArrayHasKey('stack', $context);
246+
$this->assertInternalType('array', $context['stack']);
248247
};
249248

250249
$logger
@@ -262,11 +261,10 @@ public function testHandleError()
262261

263262
$logger = $this->getMock('Psr\Log\LoggerInterface');
264263

265-
$that = $this;
266-
$logArgCheck = function ($level, $message, $context) use ($that) {
267-
$that->assertEquals('Undefined variable: undefVar', $message);
268-
$that->assertArrayHasKey('type', $context);
269-
$that->assertEquals($context['type'], E_NOTICE);
264+
$logArgCheck = function ($level, $message, $context) {
265+
$this->assertEquals('Undefined variable: undefVar', $message);
266+
$this->assertArrayHasKey('type', $context);
267+
$this->assertEquals($context['type'], E_NOTICE);
270268
};
271269

272270
$logger
@@ -300,11 +298,10 @@ public function testHandleException()
300298

301299
$logger = $this->getMock('Psr\Log\LoggerInterface');
302300

303-
$that = $this;
304-
$logArgCheck = function ($level, $message, $context) use ($that) {
305-
$that->assertEquals('Uncaught Exception: foo', $message);
306-
$that->assertArrayHasKey('type', $context);
307-
$that->assertEquals($context['type'], E_ERROR);
301+
$logArgCheck = function ($level, $message, $context){
302+
$this->assertEquals('Uncaught Exception: foo', $message);
303+
$this->assertArrayHasKey('type', $context);
304+
$this->assertEquals($context['type'], E_ERROR);
308305
};
309306

310307
$logger
@@ -322,9 +319,8 @@ public function testHandleException()
322319
$this->assertSame($exception, $e);
323320
}
324321

325-
$that = $this;
326-
$handler->setExceptionHandler(function ($e) use ($exception, $that) {
327-
$that->assertSame($exception, $e);
322+
$handler->setExceptionHandler(function ($e) use ($exception) {
323+
$this->assertSame($exception, $e);
328324
});
329325

330326
$handler->handleException($exception);
@@ -353,11 +349,10 @@ public function testHandleFatalError()
353349

354350
$logger = $this->getMock('Psr\Log\LoggerInterface');
355351

356-
$that = $this;
357-
$logArgCheck = function ($level, $message, $context) use ($that) {
358-
$that->assertEquals('Fatal Parse Error: foo', $message);
359-
$that->assertArrayHasKey('type', $context);
360-
$that->assertEquals($context['type'], E_ERROR);
352+
$logArgCheck = function ($level, $message, $context) {
353+
$this->assertEquals('Fatal Parse Error: foo', $message);
354+
$this->assertArrayHasKey('type', $context);
355+
$this->assertEquals($context['type'], E_ERROR);
361356
};
362357

363358
$logger
@@ -391,11 +386,10 @@ public function testDeprecatedInterface()
391386

392387
$logger = $this->getMock('Psr\Log\LoggerInterface');
393388

394-
$that = $this;
395-
$logArgCheck = function ($level, $message, $context) use ($that) {
396-
$that->assertEquals('Undefined variable: undefVar', $message);
397-
$that->assertArrayHasKey('type', $context);
398-
$that->assertEquals($context['type'], E_NOTICE);
389+
$logArgCheck = function ($level, $message, $context) {
390+
$this->assertEquals('Undefined variable: undefVar', $message);
391+
$this->assertArrayHasKey('type', $context);
392+
$this->assertEquals($context['type'], E_NOTICE);
399393
};
400394

401395
$logger

0 commit comments

Comments
 (0)
0