Comments (9)
Some libraries expect some keys to be string and others to not be set, and since it's an external library I cannot change how it accepts the array.
Any array item without an explicit key, automatically gets assigned an integer key. You can fix the issue by using explicit integer keys yourself, like so:
array(
'relation' => 'AND',
0 => array( 'key' => 'foo' ),
1 => array( 'key' => 'bar' ),
)
No need for disables/ignores. Either fix the issue or don't use this sniff.
from phpcsextra.
Adding the default numeric keys just makes it harder to maintain. Some months later, I add an array at position 2 - then I have to manually change all following 20 elements too.
This makes it a pain to work with and also the git diffs are less clear.
from phpcsextra.
@kkmuffme Again, in that case, this is just not a suitable sniff for your usecase.
from phpcsextra.
I know I can phpcs:disable, but for 90% of my code this sniff works perfectly fine and makes sense.
But in 10% I have some external libs, that have the above issue - I can of course phpcs:disable each and every time, but an ignore option would be much better, as I'd only have to set this in the config once.
from phpcsextra.
Another way to still use the sniff, but avoid this particular issue is as follows:
$array = array(
array( 'key' => 'foo' ),
array( 'key' => 'bar' ),
);
$array['relation'] = 'AND';
I don't particularly like that code pattern, but it would avoid the sniff flagging the array.
an ignore option would be much better, as I'd only have to set this in the config once.
An ignore option will not be accepted for this sniff as you then get the next request: "this key should only be ignored in combination with that key", "this key should only be ignored in file x.php" etc. This is a road to maintainer pain which I'm not willing to take.
from phpcsextra.
Another way to still use the sniff, but avoid this particular issue is as follows:
I have a nested config array, so this won't work without massively bloating the code.
"this key should only be ignored in combination with that key"
Well, let's cross the bridge when we come to it :-) and start with a simple ignore. Anything further can then be discussed IF anybody really needs that.
"this key should only be ignored in file x.php"
This is already supported by this rule, since this is a native feature of phpcs.
Would you accept a PR for a simple "ignore" case, where all keys in the ignore array are treated as if they're not part of the array at all? (ignored)
from phpcsextra.
This is already supported by this rule, since this is a native feature of phpcs.
It is not, as properties are per sniff and not configurable per file.
Would you accept a PR for a simple "ignore" case, where all keys in the ignore array are treated as if they're not part of the array at all? (ignored)
As I've stated three times now: no, I would not.
from phpcsextra.
It is not, as properties are per sniff and not configurable per file.
phpcs:disable in the file comment, does precisely this though?
from phpcsextra.
It is not, as properties are per sniff and not configurable per file.
phpcs:disable in the file comment, does precisely this though?
No it does not. It disables the complete sniff for a file. Not apply a specific property exclusively to a specific file.
from phpcsextra.
Related Issues (20)
- Question: what scenarios would using post inc/dec cause issues if code were moved around? HOT 3
- Add the unneeded ternary sniff HOT 1
- Sniff(s) to detect proper usage of preg_quote()
- Sniff to detect the irregular whitespace characters HOT 3
- Sniff to discourage "long" closures
- False positive in Universal.CodeAnalysis.ConstructorDestructorReturn HOT 3
- Incorrect detection of PHP 4-style constructors by Universal.CodeAnalysis.ConstructorDestructorReturn HOT 9
- Sniff to enforce naming conventions for namespace names
- Sniff to enforce naming conventions for class/function/const aliases
- Sniff to detect useless alias names HOT 1
- Sniff to flag `is_a()` and possibly replace with `instanceof`
- Universal.Arrays.MixedArrayKeyTypes should report on explicit keys, if implicit keys are the majority HOT 2
- Add option to NormalizedArrays.Arrays.ArrayBraceSpacing to allow single- or multi-line empty arrays HOT 4
- preg_replace replacement with variable must be wrapped in addcslashes HOT 1
- Problem with NormalizedArrays.Arrays.CommaAfterLast in some cases HOT 7
- Feature suggestion: new sniff `EchoConcatenation`
- Potential new sniff: scan code for "Trojan source"
- Feature suggestion: new sniff for detecting brand name or text string HOT 1
- Add Sniff to ensure file only uses PHP native functions or functions defined in the current file HOT 1
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 phpcsextra.