There are places with:
$pattern = variable_get('bar', FALSE);
if (!trim($pattern)) {
and others with:
$pattern = trim(variable_get('bar', ''));
if (!$pattern) {
... and some white spaces.
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | pathauto_code_style_262774-30.d5.patch | 10.83 KB | Freso |
| #26 | pathauto_code_style_262774-23.patch | 13.74 KB | Freso |
| #21 | pathauto_code_style_262774-21.patch | 11.94 KB | Freso |
| #19 | pathauto_code_style_262774-19.patch | 9.24 KB | Freso |
| #12 | pathauto_262774.patch | 6.67 KB | dvinegla |
Comments
Comment #1
dvinegla commentedComment #2
Freso commentedYou have a
$patern = '';which should be$pattern = '';. I'll leave this for Greg to review properly though, as he may know of a reason why the trims are done the way they are. (Also, you can find more (trailing) whitespace if you use Coder. ;))Comment #3
dvinegla commented$patern = '' -> $pattern = ''
Comment #4
Freso commentedPatch doesn't apply cleanly anymore. Please re-roll.
Comment #5
dvinegla commentedchasing HEAD.
Comment #6
Freso commentedComment #7
gregglesThe if (!$pattern) checks are not E_NOTICE compliant, which is something that a "code style" patch should also fix.
I'm also not sure that moving the trim() above is any clearer nor am I really sure that it's necessary...so, perhaps we can just drop that and change these to
if (isset($pattern) && $pattern) {The whitespace changes seem fine to me.
Comment #8
dvinegla commentedThis is why I always inicialize the variable $pattern: $pattern = '';
$pattern=trim(variable_get(.....
if ($pattern) {
you obtains a trimed pattern
$pattern = variable_get(...
if (trim($pattern)) {
you obtains a not trimed pattern
what do you prefer?
if you have a pattern like this: $pattern= ' ' (white space), it pass the check.
Comment #9
Freso commentedThis won't do:watchdog('pathauto', $update_msg);.watchdog()should be fed the "raw", untranslated string and then handle the translation when displaying the message in the logs. I'm not sure how to handle plurals withinwatchdog()though, so this might have to be looked into.Also, I'd vote for waiting with committing this for 6.x-2.x.D'oh! Commented on wrong issue. My bad. :x
Comment #10
Freso commentedComment #11
Freso commentedOkay, here's the deal Greg and I just agreed on:
We want the variables stored with
trim(), ie.$pattern = trim(...).We want to use
!empty()to check that the variable exists (and contains something), ie.!empty($pattern). This should also remove the need to initialise the variables before time, right?Please let me/us know if we're out of our minds! :)
Comment #12
dvinegla commentedre-roll and apply #11
Comment #13
Freso commentedThis is looking good. Thank you for your work on this! :)
If you're up to the task, there are some instances of
if (isset($var) && $var), and changing these toif (!empty($var))would be a nice addition to this code style clean-up. :) (If not, that's alright too, and this patch is close, if not ready, to being committed.)Comment #14
dvinegla commentedI found if with "and" and others with "&&", change and to && or leave them?
Comment #15
Freso commentedHm. I'm not completely sure what you mean... ? Both
if (isset($var) and $var)andif (isset($var) && $var)should beif (!empty($var)), as far as I can tell... but yeah, if there are anyand's floating about outside of such a statement, they should probably be made to&&'s, for consistency. :)Comment #16
dvinegla commentedif ($verbose and user_access('notify of path changes')) {
Comment #17
Freso commentedRight, that should be changed to
&&(for consistency). :)Oh, and good catch!
Comment #18
Freso commentedJust a note:
pathauto_user()has$new_user->roles = isset($edit['roles']) ? $edit['roles']: array();which should have a space before the colon. (This is only in the 6.x branch.)Comment #19
Freso commentedA couple of hunks didn't apply anymore, so I re-rolled and incorporated some of the changes mentioned above.
Comment #20
gregglesLooks good to me.
Comment #21
Freso commentedWhile reading through the code again, I stumbled across this:
if (!isset($node->pathauto_perform_alias) || $node->pathauto_perform_alias)"If
$varis not set OR if it is true." Is this necessary? There are only ever so few cases where$node->pathauto_perform_aliaswon't fulfill either of those states... so I'm thinking that either one of them could probably go, or they both could... ?Similarly, instances like
if (isset($old_alias) && drupal_strlen($old_alias))could probably be replaced withif (!empty($old_alias))as well, as the only timedrupal_strlen($old_alias)will return something other than 0, is on a non-empty string. Thus, this should theoretically be an ever so slight performance increase as well. Any objections/reasons not to do this? :)An updated patch (without changing anything mentioned above) attached, which also includes some double to single string conversion.
Comment #22
gregglesThe pathauto_perform_alias stuff is very twitchy - it took a long time to work out a bunch of edge cases (user creates/edits nodes and does/doesn't have permission to create path aliases and node has a pattern set/doesn't but follows default). So, I'm hesitant to change that...
The second item you point out makes sense to me.
Comment #23
Freso commentedSince
empty($var)returns true if$varis '0' (ie, a one character string containing the character "0"), we might not want to do this. But then, why not? If people "hardcode" their patterns to be "0", I'd say they're asking for trouble anyway. The only problem would be if people use something like "[title-raw]" (ie., where the title (or another, single token) is all there is in the pattern), where the title happened to be "0" - which might just happen. So I'm unsure of what to do. (I'll try and do some testing to see the actual results with and without this patch.)But here's an updated patch; including a re-roll, some array code style fixin', and the
empty()mentioned in the second part of comment #21. Also, I might commit a temporary patch based on this, without theempty()changes. I'll make a comment here if I do.Comment #24
Freso commentedEh. And the patch.
Comment #25
Freso commentedHuh? Hm... third time's the charm, no?
Comment #26
Freso commentedHm. It seems I'm being hit by #267884: Attachments failing when users preview or use "attach" button... so I'll try again.
Edit: Yay! :D
Comment #27
Freso commentedOkay, here's the deal on using
empty(), from what my quick testing revealed._not_zero(or something) to do both?Comment #28
Freso commentedAbout bullet #2 above, check #268909: "0" can't be used a path alias, but no error is shown for development on this. :)
Comment #29
Freso commentedAnyway, the test returns no errors with current patch, so I committed this. If the
empty()'ies turn out to be problematic, we can weed through which ones are causing problems and try something else (if (empty($var) && strlen($var) < 1)perhaps?).Also, we should do this normalisation on the 5.x branch as well.
Comment #30
Freso commentedI love how patches apply almost 1:1 between 6.x-1.x and 5.x-2.x. :)
If nobody is quick to step up and object to this, I'll apply it soonishly.
Comment #31
Freso commentedAnd... committed.
Comment #32
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.