Comments (14)
In case somebody is searching for those issues and try to fix by themself, below is regex, what worked about 95% of situations (eg, will not match closure function in method).
OneLiners concatenated together by OR (|):
([a-zA-Z0-9$]|[ ])+->\w*\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(|\((new .*)\)\)->\w*\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(|([a-zA-Z0-9])+\:\:\w*\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(|[a-zA-Z0-9$]+->\w*\((([^\(\)]+|))\)\n[ ]*->[a-zA-Z0-9$]+\(|\((new .*)\)\)->\w*\((([^\(\)]+|))\)\n[ ]*->[a-zA-Z0-9$]+\(|[a-zA-Z0-9$]+\n[ ]*->[a-zA-Z0-9$]+\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(|\((new .*)\)\)\n[ ]*->[a-zA-Z0-9$]+\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(
Explanation
1.1 Search for single line multiple chain, no rounded brackets [^\(\)] in selection.
Pattern: $object->method1($attributes)->method2(
Regex: ([a-zA-Z0-9$]|[ ])+->\w*\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(
1.2 The same as above, but for new objects.
Pattern: (new Object())->method1($attributes)->method2(
Regex: \((new .*)\)\)->\w*\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(
1.3 The same as 1.1, but for static methods
Pattern: Object::method1($attributes)->method2(
Regex: ([a-zA-Z0-9])+\:\:\w*\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(
2.1 Search for multiple line multiple chain (first method on the same line as object - chaining).
Pattern:
$object->method1($attributes)
->method2(
Regex: [a-zA-Z0-9$]+->\w*\((([^\(\)]+|))\)\n[ ]*->[a-zA-Z0-9$]+\(
2.2 The same as above, but for new objects.
Pattern:
(new Object())->method1($attributes)
->method2(
Regex: \((new .*)\)\)->\w*\((([^\(\)]+|))\)\n[ ]*->[a-zA-Z0-9$]+\(
3.1 Search for multiple line multiple chain (first method on the next line second method on the same line as first method - chaining).
Pattern:
$object
->method1($attributes)->method2(
Regex: [a-zA-Z0-9$]+\n[ ]*->[a-zA-Z0-9$]+\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(
3.2 The same as above, but for new objects.
Pattern:
(new Object())
->method1($attributes)->method2(
Regex: \((new .*)\)\)\n[ ]*->[a-zA-Z0-9$]+\((([^\(\)]+|))\)->[a-zA-Z0-9$]+\(
Use with care :)
from docs.
More examples (I had during code review), are they correct?
one argument (single method) with concatenation:
$this->assertGreaterThan($customerQuery->count() . " " . print_r($orders, true));
one argument (chain calls):
$this->assertCount(
$query
->createCommand()
->getRawSql()
);
multiple arguments (single/chained), with concatenation:
$this->assertCount(
1,
$orders,
$query
->createCommand()
->getRawSql() .
print_r($orders, true)
);
chaining in if() with multiple conditions:
if (
$db
->getSchema()
->getTableSchema($tablename, true) === null
) {
// code
}
property after method:
$this->assertFalse(
$boolARQuery
->where(['bool_col' => false])
->one()->bool_col
);
from docs.
I usually do it as:
$object
->method1()
->method2();
from docs.
We may have it as a soft-rule with should
instead of must
.
from docs.
Yes, it is.
from docs.
Already checked and seems it can't be automated with StyleCI.
from docs.
I usually do it as:
$object ->method1() ->method2();
Me too, and also when chain is long sometime writes it as:
$object
->methot1()
->methot2()
->methot3()
->methot4()
->methot5()
;
to easy move/remove any method.
from docs.
This rule is overhead for me. Don't want to significantly expand the PSR-12.
Although, I prefer @samdark variant:
$object
->method1()
->method2();
from docs.
What about such inliners?
in array (from: yii3-app/config/routes.php):
return [
Route::get('/')->action([SiteController::class, 'index'])->name('home'),
];
as variable (yii3-app/tests/Unit/HelloCest.php):
$params = $this->getConfig()->get('params');
as return (yii3-app/tests/Support/_generated/UnitTesterActions.php):
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
It will be more clear if it would be stated here as examples of different usage cases.
from docs.
Is this correct?
return [
Route::get('/')
->action([SiteController::class, 'index'])
->name('home'),
];
$params = $this
->getConfig()
->get('params');
return $this
->getScenario()
->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
from docs.
@sankaest merged all PRs opened so far. Thanks!
from docs.
Use with care! and save your time!
No one will use it. It can be implemented as a plugin to such tools as php-cs-fixer, rector, prettier or others.
from docs.
Well, if somebody will make a plugin I will be happy. At least until now, no changes were made and as @arogachev was pointed out: "Already checked and seems it can't be automated with StyleCI." And within two month, nobody made any changes according to this issue. But if somebody will make a plugin, let me know, so I could be happy. :) @xepozz can you make it?
from docs.
Well, if somebody will make a plugin I will be happy. At least until now, no changes were made and as @arogachev was pointed out: "Already checked and seems it can't be automated with StyleCI." And within two month, nobody made any changes according to this issue. But if somebody will make a plugin, let me know, so I could be happy. :) @xepozz can you make it?
I don't think so :)
StyleCI should be omitted as for me.
So with php-cs-fixer you can create your own rule. It's simple.
https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/custom_rules.rst
from docs.
Related Issues (20)
- Have rules about resolving discussions / conversations in code review HOT 4
- Add Related packages section HOT 2
- update CODE_OF_CONDUCT.md links
- update yii site links
- update links
- broken links
- Add Rule and Rule Handler to glossary
- Add common PHPStorm config
- Document explicit `null` type hint HOT 5
- Configure max line length
- Code style summary to discuss and configure HOT 4
- Automatically add line breaks for long lines in Markdown HOT 1
- Automatically detect broken links
- Link to the next chapter where it makes sense
- Yiisoft\Form\YiisoftFormModel\FormModel is not exist HOT 1
- Add git branches flow description HOT 1
- Add usage of KV cache to RoadRunner docs
- update es folder links
- Use Swoole instead of OpenSwoole
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.