Result of || is always true

Created on 19 January 2024, 10 months ago
Updated 8 March 2024, 9 months ago

Problem/Motivation

Running phpstan at level 4 or higher produces the following error:

 ------ ------------------------------ 
  Line   src/TruncateHTML.php          
 ------ ------------------------------ 
  271    Result of || is always true.  
 ------ ------------------------------ 

The line flagged in the error is:

if (in_array($domnode->parentNode->nodeName, $avoid) && ($domnode->parentNode->parentNode !== NULL || $domnode->parentNode->parentNode !== $this->startNode)) {

I'm not quite sure why it thinks the or condition will always evaluate true, but it seems slightly confusingly written to me, so I think it would be worth reworking to make it clearer.

Steps to reproduce

Run phpstan analyze --level 5

Proposed resolution

I don't know exactly what the fix should be, but the condition could be reworked.

Remaining tasks

  • Come up with improved condition
  • Raise phpstan level to 5

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Needs work

Version

2.1

Component

Code

Created by

🇮🇪Ireland lostcarpark

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @lostcarpark
  • First commit to issue fork.
  • Assigned to himanshu_jhaloya
  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • 🇮🇳India himanshu_jhaloya Indore

    Created MR. fixed the error. Please review

  • Pipeline finished with Failed
    9 months ago
    Total: 227s
    #101670
  • 🇮🇪Ireland lostcarpark

    What have you changed? I can't see any change to the if statement, apart from some trailing spaces, which cause PHPCS to fail.

  • Status changed to Needs work 9 months ago
  • Assigned to himanshu_jhaloya
  • 🇮🇳India himanshu_jhaloya Indore

    Hi @lostcarpark I run the phpstan analyze --level 5
    that errors are getting

    vendor/bin/phpstan analyse --level 5 web/modules/contrib/smart_trim-3415976/

    ------ ------------------------------
    Line src/TruncateHTML.php
    ------ ------------------------------
    271 Result of || is always true.
    ------ ------------------------------

    ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Line tests/src/Functional/SmartTrimFunctionalTest.php
    ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------
    17 Class Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest extends unknown class Drupal\Tests\BrowserTestBase.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    58 Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::setUp() calls parent::setUp() but Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest does not
    extend any class.
    60 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::createContentType().
    62 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::config().
    63 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalCreateUser().
    64 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalCreateUser().
    65 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::createAdminRole().
    67 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalLogin().
    69 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalCreateNode().
    70 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::randomString().
    79 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalCreateNode().
    80 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::randomString().
    89 Call to static method create() on an unknown class Drupal\node\Entity\NodeType.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    92 Call to static method create() on an unknown class Drupal\field\Entity\FieldStorageConfig.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    98 Call to static method create() on an unknown class Drupal\field\Entity\FieldConfig.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    105 Call to static method create() on an unknown class Drupal\node\Entity\Node.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    108 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::randomString().
    118 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    119 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    131 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    132 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::getSession().
    133 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    143 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    154 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    161 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    162 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::submitForm().
    178 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    189 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    196 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    197 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::submitForm().
    213 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    221 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    238 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    248 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    265 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    294 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    295 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    296 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    297 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    298 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    299 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    300 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    301 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    302 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    303 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    304 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    327 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    328 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    329 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    330 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    331 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    332 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    333 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    334 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    335 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    336 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    337 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    362 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    363 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    364 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    365 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    366 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    367 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    368 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    369 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    370 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    371 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    372 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    397 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    398 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    399 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEmpty().
    420 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    421 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    422 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertCount().
    447 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    448 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    449 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEquals().
    452 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    453 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEquals().
    478 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    479 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    480 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEquals().
    505 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    506 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    507 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEquals().
    531 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    532 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    533 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEquals().
    557 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    558 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    559 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEquals().
    561 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    562 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEquals().
    591 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    592 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    593 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertEquals().
    615 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    616 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::xpath().
    617 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertNull().
    624 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    644 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    665 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    686 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    696 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::assertSession().
    713 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    729 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimFunctionalTest::drupalGet().
    ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------

    ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Line tests/src/Functional/SmartTrimHooksTest.php
    ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------
    13 Class Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest extends unknown class Drupal\Tests\BrowserTestBase.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    48 Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::setUp() calls parent::setUp() but Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest does not extend any
    class.
    50 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::createContentType().
    51 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::drupalCreateUser().
    52 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::drupalLogin().
    54 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::drupalCreateNode().
    55 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::randomString().
    91 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::drupalGet().
    94 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::xpath().
    95 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::assertCount().
    98 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::xpath().
    99 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimHooksTest::assertCount().
    ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------

    ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------
    Line tests/src/Functional/SmartTrimTemplateTest.php
    ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------
    15 Class Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest extends unknown class Drupal\Tests\BrowserTestBase.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    49 Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::setUp() calls parent::setUp() but Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest does not
    extend any class.
    51 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::createContentType().
    53 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::config().
    54 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalCreateUser().
    55 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::createAdminRole().
    57 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalLogin().
    60 Call to static method create() on an unknown class Drupal\field\Entity\FieldStorageConfig.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    66 Call to static method create() on an unknown class Drupal\field\Entity\FieldConfig.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    74 Call to static method create() on an unknown class Drupal\field\Entity\FieldStorageConfig.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    80 Call to static method create() on an unknown class Drupal\field\Entity\FieldConfig.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    87 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalCreateNode().
    88 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::randomString().
    148 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalGet().
    151 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    152 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    155 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    156 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    159 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    160 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    206 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalGet().
    209 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    210 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    211 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    214 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    215 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    216 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    219 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    220 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    222 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertEquals().
    230 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::createContentType().
    231 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalCreateNode().
    232 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::randomString().
    240 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalGet().
    241 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    242 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertCount().
    243 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    244 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertCount().
    245 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    246 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertCount().
    247 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    248 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertCount().
    249 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    250 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertCount().
    251 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::xpath().
    252 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertCount().
    275 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalGet().
    276 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertSession().
    294 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::drupalGet().
    295 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTemplateTest::assertSession().
    ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------

    ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------
    Line tests/src/Functional/SmartTrimTranslationTest.php
    ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------
    13 Class Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest extends unknown class Drupal\Tests\BrowserTestBase.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    49 Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::setUp() calls parent::setUp() but Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest does
    not extend any class.
    51 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::createContentType().
    52 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::drupalCreateUser().
    53 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::drupalLogin().
    55 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::drupalCreateNode().
    56 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::randomString().
    65 Function smart_trim_translation_test_add_translation not found.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    66 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::config().
    94 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::drupalGet().
    97 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::xpath().
    98 Call to an undefined method Drupal\Tests\smart_trim\Functional\SmartTrimTranslationTest::assertCount().
    ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------

    ------ -------------------------------------------------------------------------------------------------------------------------------------------------
    Line tests/src/Functional/Update/SmartTrimUpdateMoreTest.php
    ------ -------------------------------------------------------------------------------------------------------------------------------------------------
    12 Class Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest extends unknown class Drupal\FunctionalTests\Update\UpdatePathTestBase.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    18 Access to an undefined property Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::$databaseDumpFiles.
    💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
    29 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::drupalCreateUser().
    30 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::createAdminRole().
    32 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::drupalLogin().
    34 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::runUpdates().
    39 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertEquals().
    40 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertTrue().
    41 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertFalse().
    42 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertFalse().
    44 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertEquals().
    45 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertEquals().
    46 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertEquals().
    48 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertArrayNotHasKey().
    49 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertArrayNotHasKey().
    50 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertArrayNotHasKey().
    51 Call to an undefined method Drupal\Tests\smart_trim\Functional\Update\SmartTrimUpdateMoreTest::assertArrayNotHasKey().
    ------ -------------------------------------------------------------------------------------------------------------------------------------------------

    ------ ----------------------------------------------------------------------------------------------------
    Line tests/src/Unit/SuggestionTest.php
    ------ ----------------------------------------------------------------------------------------------------
    14 Class Drupal\Tests\smart_trim\Unit\SuggestionTest extends unknown class Drupal\Tests\UnitTestCase.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    25 Function smart_trim_theme_suggestions_smart_trim_alter not found.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    27 Call to an undefined method Drupal\Tests\smart_trim\Unit\SuggestionTest::assertSame().
    30 Call to an undefined method Drupal\Tests\smart_trim\Unit\SuggestionTest::assertContains().
    ------ ----------------------------------------------------------------------------------------------------

    ------ ------------------------------------------------------------------------------------------------------
    Line tests/src/Unit/TruncateHTMLTest.php
    ------ ------------------------------------------------------------------------------------------------------
    17 Class Drupal\Tests\smart_trim\Unit\TruncateHTMLTest extends unknown class Drupal\Tests\UnitTestCase.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    28 Call to an undefined method Drupal\Tests\smart_trim\Unit\TruncateHTMLTest::assertSame().
    108 Call to an undefined method Drupal\Tests\smart_trim\Unit\TruncateHTMLTest::assertSame().
    212 Call to an undefined static method Drupal\Tests\smart_trim\Unit\TruncateHTMLTest::assertEquals().
    ------ ------------------------------------------------------------------------------------------------------

    [ERROR] Found 206 errors

  • Issue was unassigned.
  • 🇮🇪Ireland lostcarpark

    @himanshu_jhaloya most of those errors report that the test base class wasn't found. I'm not getting this error, so I can't help wonder is it related to your Drupal core install? Can you try running at level 3? We know that should not return any PHPSTAN errors, because it's passing in GitLab CI.

  • 🇮🇳India himanshu_jhaloya Indore

    Thank @lostcarpark I try running at level 3

  • 🇮🇳India himanshu_jhaloya Indore

    Level 3 I did found any error on the src/TruncateHTML.php
    on the level 5 i got this
    ubuntu@ubuntu-Inspiron-15-3567:/var/www/html/contribution/drupal-10$ vendor/bin/phpstan analyse --level 5 web/modules/contrib/smart_trim-3415976/src/TruncateHTML.php
    1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

    ------ ------------------------------
    Line TruncateHTML.php
    ------ ------------------------------
    271 Result of || is always true.
    ------ ------------------------------

    [ERROR] Found 1 error

    after the update code

    vendor/bin/phpstan analyse --level 5 web/modules/contrib/smart_trim-3415976/src/TruncateHTML.php
    1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

    [OK] No errors

    after added changes

    ubuntu@ubuntu-Inspiron-15-3567:/var/www/html/contribution/drupal-10$ vendor/bin/phpstan analyse --level 5 web/modules/contrib/smart_trim-3415976/src/TruncateHTML.php
    1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

    [OK] No errors

  • 🇮🇳India himanshu_jhaloya Indore

    Hi @lostcarpark can you Please review with new PR

  • Merge request !85Draft: Issue 3415976 → (Open) created by himanshu_jhaloya
  • 🇮🇪Ireland lostcarpark

    Hi @himanshu_jhaloya,

    Comment #12 looks promising, but MR !85 doesn't seem to contain any changes. Is it possible you forgot to commit before pushing the change?

    Also, I think some explanation of what you are trying to change in line 271 would be really helpful.

    Here are the steps that I think are needed:

    1. Analyze line 271 of TruncateHTML.php and determine what the comparison it trying to do, and why PHPSTAN thinks it will always return true.
    2. Rework the expression in a way that PHPSTAN doesn't object to, while keeping the behaviour unchanged in both manual and automated tests.
    3. Update the phpstan.neon file to set level: 5, then verify the CI tests are passing.

    I think a clear explanation of step 1 above would be a really useful contribution, and would allow discussion of the best way forward.

  • 🇮🇳India himanshu_jhaloya Indore

    Hi @lostcarpark I am sorry can you please check now I have updated the MR.

  • Pipeline finished with Failed
    9 months ago
    Total: 234s
    #102509
  • 🇮🇪Ireland lostcarpark

    Hi @himanshu_jhaloya,

    Thanks for your update. I see you've changed the || to &&. This may be the correct change, but I'm not convinced we understand why this logic was used in the first place.

    What is PHPSTAN complaining about?

    The "or" expression is in the following clause:

    ($domnode->parentNode->parentNode !== NULL || $domnode->parentNode->parentNode !== $this->startNode)

    This is saying "If the parent node is not NULL OR the parent nod is not the start node".

    So if the parent node is NULL, then it cannot be the start node, so the clause will evaluate true.

    Likewise, if the parent node is the start node, then it cannot be NULL, so it will also evaluate true.

    And if it's anything else, it's not either of those, so it will still evaluate true.

    When was this introduced?

    I've run the following git blame statement to find out when this line was introduced:

    git blame -n -L 271,271 src/TruncateHTML.php
    3e01ab3d src/Truncate/TruncateHTML.php 257 (Mark Casias 2015-01-11 20:16:05 -0700 271)     if (in_array($domnode->parentNode->nodeName, $avoid) && ($domnode->parentNode->parentNode !== NULL || $domnode->parentNode->parentNode !== $this->startNode)) {

    It turns out it was this issue #2363123: Trim excluding HTML (without stripping) , back in 2015, which is when the TruncateHTML class was introduced. It seems to have been based on this blog post: https://www.pjgalbraith.com/truncating-text-html-with-php/

    However, it seems that quite a bit of logic was added to the code in the post. In the post, the equivalent line is:

    if( in_array($domNode->parentNode->nodeName, $avoid) && $domNode->parentNode->parentNode !== NULL) {
    

    This does not have the second part of the "or" clause.

    What does it actually do?

    As far as I can see, this function is doing is working out where to add the ellipsis. If the string is terminating at one of a specified list of tags, it inserts a DOM node outside that tag. If it's not on that list, it just appends the ellipsis to the last DOM node before it terminates. I think, for example, it might cause:

    <p>This is a <a href="whatever">link to my site</a></p>

    to be trimmed to:

    <p>This is a <a href="whatever">link to</a>...</p>

    instead of:

    <p>This is a <a href="whatever">link to...</a></p>

    The difference being the ellipsis getting added outside of the link instead of inside it.

    I think some work is needed to look at where this causes the ellipsis to be added to specific HTML strings, and if there are cases where it could insert in the wrong place.

    It could be worth developing some test cases to verify it is behaving as expected.

    What should we do about it?

    I can see four possible solutions:

    We could just leave it as it is, since it's been working for 9 years. I'm not in favour of this, since I think PHPSTAN is correct that this always evaluates TRUE, and leaving as is will prevent us from raising our PHPSTAN level.
    We could remove the "or" clause entirely, since it always evaluates true, removing it will keep the current functionality as present.
    We could restore the functionality of the original blog post, by removing the second condition of the "or" clause.
    We could accept @himanshu_jhaloya's proposal and convert the "or" to an "and". I feel some more work is needed to determine if this is the intended logic, but if we can confirm that, this would seem the best solution.

    I feel that we need test cases to verify the intended logic so we can unsure the solution we adopt is the right one.

Production build 0.71.5 2024