Skip to content

Commit a248b02

Browse files
authored
6.x: rename conflicting underscored methods (#313)
* rename conflicting underscored methods * adjust naming according to feedback
1 parent f0551ad commit a248b02

File tree

1 file changed

+86
-23
lines changed

1 file changed

+86
-23
lines changed

config/rector/sets/cakephp60.php

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
],
8282
],
8383
'Collection' => [
84-
// _extract can't be easily renamed to extract as it conflicts with the CollectionTrait::extract() method
8584
'Cake\Collection\ExtractTrait' => [
8685
'_propertyExtractor', '_simpleExtract', '_createMatcherFilter',
8786
],
@@ -109,7 +108,6 @@
109108
'Console' => [
110109
'Cake\Console\HelpFormatter' => ['_generateUsage', '_getMaxLength'],
111110
'Cake\Console\ConsoleIo' => ['_getInput'],
112-
// _write can't be renamed to write as it conflicts with the ConsoleOutput::write() method
113111
'Cake\Console\ConsoleOutput' => ['_replaceTags'],
114112
'Cake\Console\ConsoleOptionParser' => [
115113
'_parseLongOption', '_parseShortOption', '_parseOption', '_optionExists', '_parseArg', '_nextToken',
@@ -244,21 +242,18 @@
244242
],
245243

246244
'Form' => [
247-
// Can't rename _execute as it conflicts with the Form::execute() method
248245
'Cake\Form\Form' => ['_buildSchema'],
249246
'Cake\Form\Schema' => ['_addField'],
250247
],
251248

252249
'Http' => [
253250
'Cake\Http\CorsBuilder' => ['_normalizeDomains'],
254251
'Cake\Http\Session' => ['_defaultConfig', '_overwrite', '_hasSession', '_timedOut'],
255-
// Can't rename _sendRequest as it conflicts with the Client::sendRequest() method
256252
'Cake\Http\Client' => [
257253
'_doRequest', '_mergeOptions', '_createRequest', '_typeHeaders',
258254
'_addAuthentication', '_addProxy', '_createAuth',
259255
],
260256

261-
// Can't rename _is as it conflicts with the ServerRequest::is() method
262257
'Cake\Http\ServerRequest' => [
263258
'_setConfig', '_acceptHeaderDetector', '_headerDetector',
264259
'_paramDetector', '_environmentDetector',
@@ -289,7 +284,6 @@
289284
'_encode',
290285
],
291286

292-
// Can't rename _send as it conflicts with the Stream::send() method
293287
'Cake\Http\Client\Adapter\Stream' => [
294288
'_buildContext', '_buildHeaders', '_buildContent', '_buildOptions',
295289
'_buildSslContext', '_buildResponse', '_open',
@@ -302,7 +296,6 @@
302296
],
303297

304298
'I18n' => [
305-
// Can't rename _parseDateTime as it conflicts with the DateTime::parseDateTime() method
306299
'Cake\I18n\DateFormatTrait' => ['_formatObject'],
307300
'Cake\I18n\Number' => ['_setAttributes'],
308301
'Cake\I18n\RelativeTimeFormatter' => ['_options', '_diffData'],
@@ -319,8 +312,6 @@
319312
'Mailer' => [
320313
'Cake\Mailer\TransportFactory' => ['_buildTransport'],
321314
'Cake\Mailer\Transport\MailTransport' => ['_mail'],
322-
// Can't rename _connect as it conflicts with the SmtpTransport::connect() method
323-
// Can't rename _disconnect as it conflicts with the SmtpTransport::disconnect() method
324315
'Cake\Mailer\Transport\SmtpTransport' => [
325316
'_bufferResponseLines', '_parseAuthType',
326317
'_auth', '_authPlain', '_authLogin', '_authXoauth2',
@@ -349,8 +340,6 @@
349340
'_mergeJoinData',
350341
],
351342
'Cake\ORM\Table' => [
352-
// Can't rename _saveMany as it conflicts with the Table::saveMany() method
353-
// Can't rename _deleteMany as it conflicts with the Table::deleteMany() method
354343
'_setFieldMatchers', '_executeTransaction', '_transactionCommitted',
355344
'_processFindOrCreate', '_getFindOrCreateQuery', '_processSave',
356345
'_onSaveSuccess', '_insert', '_newId', '_update', '_processDelete', '_dynamicFinder',
@@ -359,8 +348,6 @@
359348
// Behaviors
360349
'Cake\ORM\Behavior' => ['_resolveMethodAliases', '_reflectionCache'],
361350
'Cake\ORM\Behavior\TreeBehavior' => [
362-
// Can't rename _moveUp/_moveDown as it conflicts with the TreeBehavior::moveUp()/moveDown() methods
363-
// Can't rename _removeFromTree as it conflicts with the TreeBehavior::removeFromTree() method
364351
'_setChildrenLevel', '_setParent', '_setAsRoot', '_unmarkInternalTree',
365352
'_getNode', '_recoverTree', '_getMax', '_sync', '_scope', '_ensureFields', '_getPrimaryKey',
366353
],
@@ -376,7 +363,6 @@
376363
'_bindNewAssociations', '_joinCondition', '_extractFinder',
377364
],
378365
'Cake\ORM\Association\HasMany' => [
379-
// Can't rename _unlink as it conflicts with the HasMany::unlink() method
380366
'_saveTarget', '_unlinkAssociated', '_foreignKeyAcceptsNull',
381367
],
382368
'Cake\ORM\Association\BelongsToMany' => [
@@ -400,8 +386,6 @@
400386

401387
// Query
402388
'Cake\ORM\Query\SelectQuery' => [
403-
// Can't rename _decorateResults as it conflicts with the DB\SelectQuery::decorateResults() method
404-
// Can't rename _execute as it conflicts with the DB\Query::execute() method
405389
'_dirty', '_addAssociationsToTypeMap',
406390
'_performCount', '_transformQuery',
407391
'_addDefaultFields', '_addDefaultSelectTypes',
@@ -448,14 +432,9 @@
448432
'_decrypt', '_decode', '_implode', '_explode',
449433
],
450434
'Cake\Utility\Hash' => [
451-
// Can't rename _filter as it conflicts with the Hash::filter() method
452-
// Can't rename _merge as it conflicts with the Hash::merge() method
453435
'_splitConditions', '_matchToken', '_matches', '_simpleOp', '_squash',
454436
],
455-
// Can't rename _wordWrap as it conflicts with the Text::wordWrap() method
456437
'Cake\Utility\Text' => ['_strlen', '_substr', '_removeLastWord'],
457-
// Can't rename _fromArray as it conflicts with the Xml::fromArray() method
458-
// Can't rename _toArray as it conflicts with the Xml::toArray() method
459438
'Cake\Utility\Xml' => ['_loadXml', '_createChild'],
460439
'Cake\Utility\MergeVariablesTrait' => ['_mergeVars', '_mergeProperty', '_mergePropertyData'],
461440
'Cake\Utility\Inflector' => ['_cache'],
@@ -472,7 +451,6 @@
472451

473452
'View' => [
474453
'Cake\View\View' => [
475-
// Can't rename _render as it conflicts with the View::render() method
476454
'_evaluate', '_getTemplateFileName', '_inflectTemplateFileName',
477455
'_checkFilePath', '_getLayoutFileName', '_getElementFileName', '_getSubPaths',
478456
'_paths', '_elementCache', '_renderElement',
@@ -494,7 +472,6 @@
494472
],
495473
'Cake\View\Helper\HtmlHelper' => ['_renderCells', '_nestedListItem'],
496474
'Cake\View\Helper\PaginatorHelper' => [
497-
// Can't rename _numbers as it conflicts with the PaginatorHelper::numbers() method
498475
'_toggledLink', '_removeAlias', '_getNumbersStartAndEnd', '_formatNumber',
499476
'_modulusNumbers', '_firstNumber', '_lastNumber',
500477
],
@@ -532,4 +509,90 @@
532509
}
533510
}
534511
}
512+
513+
// Rename methods that start with an underscore to a new, non-conflicting name.
514+
515+
$map = [
516+
'Console' => [
517+
'Cake\Console\ConsoleOutput' => [
518+
'_write' => 'writeStream',
519+
],
520+
],
521+
'Form' => [
522+
'Cake\Form\Form' => [
523+
'_execute' => 'process',
524+
],
525+
],
526+
'Http' => [
527+
'Cake\Http\Client' => [
528+
'_sendRequest' => 'processRequest',
529+
],
530+
'Cake\Http\ServerRequest' => [
531+
'_is' => 'isType',
532+
],
533+
'Cake\Http\Client\Adapter\Stream' => [
534+
'_send' => 'processRequest',
535+
],
536+
],
537+
'I18n' => [
538+
'Cake\I18n\DateFormatTrait' => [
539+
'_parseDateTime' => 'processDateTime',
540+
],
541+
],
542+
'Mailer' => [
543+
'Cake\Mailer\Transport\SmtpTransport' => [
544+
'_connect' => 'connectSmtp',
545+
'_disconnect' => 'disconnectSmtp',
546+
],
547+
],
548+
'ORM' => [
549+
'Cake\ORM\Table' => [
550+
'_saveMany' => 'doSaveMany',
551+
'_deleteMany' => 'doDeleteMany',
552+
],
553+
'Cake\ORM\Behavior\TreeBehavior' => [
554+
'_moveUp' => 'doMoveUp',
555+
'_moveDown' => 'doMoveDown',
556+
'_removeFromTree' => 'doRemoveFromTree',
557+
],
558+
'Cake\ORM\Association\HasMany' => [
559+
'_unlink' => 'doUnlink',
560+
],
561+
'Cake\ORM\Query\SelectQuery' => [
562+
'_decorateResults' => 'ormDecorateResults',
563+
'_execute' => 'ormExecute',
564+
],
565+
],
566+
'Utility' => [
567+
'Cake\Utility\Hash' => [
568+
'_filter' => 'doFilter',
569+
'_merge' => 'doMerge',
570+
],
571+
'Cake\Utility\Text' => [
572+
'_wordWrap' => 'doWordWrap',
573+
],
574+
'Cake\Utility\Xml' => [
575+
'_fromArray' => 'doFromArray',
576+
'_toArray' => 'doToArray',
577+
],
578+
],
579+
'View' => [
580+
'Cake\View\View' => [
581+
'_render' => 'renderFile',
582+
],
583+
'Cake\View\Helper\PaginatorHelper' => [
584+
'_numbers' => 'buildNumbers',
585+
],
586+
],
587+
];
588+
589+
foreach ($map as $definitions) {
590+
foreach ($definitions as $className => $methods) {
591+
foreach ($methods as $oldMethod => $newMethod) {
592+
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
593+
new MethodCallRename($className, $oldMethod, $newMethod),
594+
]);
595+
}
596+
}
597+
}
535598
};

0 commit comments

Comments
 (0)