FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=17602&edit=1

ID: 17602
Updated by: gsherwood@squiz.net
Reported By: innovabit at gmail dot com
Summary: Problem counting blank spaces when using substr
-Status: Open
+Status: Feedback
Type: Bug
Package: PHP_CodeSniffer
Operating System: Ubuntu
Package Version: 1.2.2
PHP Version: 5.3.2
-Assigned To:
+Assigned To: squiz
Roadmap Versions:
New Comment:

-Status: Open
+Status: Feedback
-Assigned To:
+Assigned To: squiz
Can you please provide sample code to reproduce the error, and what the
error
message actually is? It looks like the code is doing exactly what it
should do; count
the number of spaces after the newline so it can report on the indent.


Previous Comments:
------------------------------------------------------------------------

[2010-07-16 10:33:24] mcordoba

Description:
------------
Line 122 ClassDeclarationSniff.php in Squiz Standard

$blankSpace = substr($prevContent, strpos($prevContent,
$phpcsFile->eolChar));

should be:

$blankSpace = substr($prevContent, 0, strpos($prevContent,
$phpcsFile->eolChar));

------------------------------------------------------------------------

Search Discussions

  • Innovabit at Jul 20, 2010 at 4:06 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=17602&edit=1

    ID: 17602
    Comment by: innovabit@gmail.com
    Reported By: innovabit at gmail dot com
    Summary: Problem counting blank spaces when using substr
    Status: Feedback
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Ubuntu
    Package Version: 1.2.2
    PHP Version: 5.3.2
    Assigned To: squiz
    Roadmap Versions:
    New Comment:

    I have this code:

    <?php
    class Prueba {

    public function __construct() {

    }
    (here blank line but with 3 spaces for example)
    }

    It must say: "Expected 0 spaces before closing brace; 3 found"

    and it says: "Expected 0 spaces before closing brace; 1 found"

    In php.net you can see:

    string substr ( string $string , int $start [, int $length ] )

    it need as param: string, start and length and start is missing.

    strpos return the lenght but the start has to be 0.

    This is the code where de problem is:

    $closeBrace = $tokens[$stackPtr]['scope_closer'];
    if ($tokens[($closeBrace - 1)]['code'] === T_WHITESPACE) {
    $prevContent = $tokens[($closeBrace - 1)]['content'];
    if ($prevContent !== $phpcsFile->eolChar) {
    $blankSpace = substr($prevContent, strpos($prevContent,
    $phpcsFile->eolChar));
    $spaces = strlen($blankSpace);
    if ($spaces !== 0) {
    $messageHandler->addMessage(Config::EXPECTED_SPACES_BEF_NAME,
    $closeBrace, array("0", $tokens[$closeBrace]['content'], $spaces));
    }
    }
    }

    The solution is change:

    $blankSpace = substr($prevContent, strpos($prevContent,
    $phpcsFile->eolChar));

    to:

    $blankSpace = substr($prevContent, 0,
    strpos($prevContent, $phpcsFile->eolChar));


    Previous Comments:
    ------------------------------------------------------------------------

    [2010-07-19 01:06:22] squiz

    -Status: Open
    +Status: Feedback
    -Assigned To:
    +Assigned To: squiz
    Can you please provide sample code to reproduce the error, and what the
    error
    message actually is? It looks like the code is doing exactly what it
    should do; count
    the number of spaces after the newline so it can report on the indent.

    ------------------------------------------------------------------------

    [2010-07-16 10:33:24] mcordoba

    Description:
    ------------
    Line 122 ClassDeclarationSniff.php in Squiz Standard

    $blankSpace = substr($prevContent, strpos($prevContent,
    $phpcsFile->eolChar));

    should be:

    $blankSpace = substr($prevContent, 0, strpos($prevContent,
    $phpcsFile->eolChar));

    ------------------------------------------------------------------------
  • Gsherwood at Jul 28, 2010 at 5:15 am
    Edit report at http://pear.php.net/bugs/bug.php?id=17602&edit=1

    ID: 17602
    Updated by: gsherwood@squiz.net
    Reported By: innovabit at gmail dot com
    Summary: Problem counting blank spaces when using substr
    -Status: Feedback
    +Status: Closed
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Ubuntu
    Package Version: 1.2.2
    PHP Version: 5.3.2
    Assigned To: squiz
    Roadmap Versions:
    New Comment:

    -Status: Feedback
    +Status: Closed
    This bug has been fixed in SVN.

    If this was a documentation problem, the fix will appear on pear.php.net
    by the end of next Sunday (CET).

    If this was a problem with the pear.php.net website, the change should
    be live shortly.

    Otherwise, the fix will appear in the package's next release.

    Thank you for the report and for helping us make PEAR better.

    Thanks for posting the code. I see where the confusion is now, although
    the sniff
    works as intended and your change actually breaks the sniff because it
    no longer
    reports an error for a space before the closing brace. It's just a
    result of it actually
    checking two different things in the same way.

    So instead, I've tried to clear up the confusion by printing two
    different messages. In
    your case, the message will now read: Expected 0 spaces before closing
    brace;
    newline found


    Previous Comments:
    ------------------------------------------------------------------------

    [2010-07-20 16:06:48] mcordoba

    I have this code:

    <?php
    class Prueba {

    public function __construct() {

    }
    (here blank line but with 3 spaces for example)
    }

    It must say: "Expected 0 spaces before closing brace; 3 found"

    and it says: "Expected 0 spaces before closing brace; 1 found"

    In php.net you can see:

    string substr ( string $string , int $start [, int $length ] )

    it need as param: string, start and length and start is missing.

    strpos return the lenght but the start has to be 0.

    This is the code where de problem is:

    $closeBrace = $tokens[$stackPtr]['scope_closer'];
    if ($tokens[($closeBrace - 1)]['code'] === T_WHITESPACE) {
    $prevContent = $tokens[($closeBrace - 1)]['content'];
    if ($prevContent !== $phpcsFile->eolChar) {
    $blankSpace = substr($prevContent, strpos($prevContent,
    $phpcsFile->eolChar));
    $spaces = strlen($blankSpace);
    if ($spaces !== 0) {
    $messageHandler->addMessage(Config::EXPECTED_SPACES_BEF_NAME,
    $closeBrace, array("0", $tokens[$closeBrace]['content'], $spaces));
    }
    }
    }

    The solution is change:

    $blankSpace = substr($prevContent, strpos($prevContent,
    $phpcsFile->eolChar));

    to:

    $blankSpace = substr($prevContent, 0,
    strpos($prevContent, $phpcsFile->eolChar));

    ------------------------------------------------------------------------

    [2010-07-19 01:06:22] squiz

    -Status: Open
    +Status: Feedback
    -Assigned To:
    +Assigned To: squiz
    Can you please provide sample code to reproduce the error, and what the
    error
    message actually is? It looks like the code is doing exactly what it
    should do; count
    the number of spaces after the newline so it can report on the indent.

    ------------------------------------------------------------------------

    [2010-07-16 10:33:24] mcordoba

    Description:
    ------------
    Line 122 ClassDeclarationSniff.php in Squiz Standard

    $blankSpace = substr($prevContent, strpos($prevContent,
    $phpcsFile->eolChar));

    should be:

    $blankSpace = substr($prevContent, 0, strpos($prevContent,
    $phpcsFile->eolChar));

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJul 19, '10 at 1:06a
activeJul 28, '10 at 5:15a
posts3
users2
websitepear.php.net

2 users in discussion

Gsherwood: 2 posts Innovabit: 1 post

People

Translate

site design / logo © 2022 Grokbase