eaudeweb / recommended-project

Project template for Drupal 10 projects
http://drupal.org/project/drupal
0 stars 0 forks source link

Supress static access warning #13

Closed Anthelixes closed 1 year ago

Anthelixes commented 2 years ago
Warning: Avoid using static access to class '\Drupal\Core\Render\Element' in method 'build'.
Warning: Avoid using static access to class '\Drupal\Core\Url' in method 'generateButton'.
cristiroma commented 2 years ago

@Anthelixes can you please provide a little bit more context on the warning above? How can it be replicated? Thanks.

Anthelixes commented 2 years ago

Create an URL using:

Url::fromRoute('entity.node.canonical', ['node' => $this->node->id()], []),

Running: ./vendor/bin/phpmd ./web/modules/custom/ github phpmd.xml will give:

::warning file=.../Plugin/Block/EventMenuBlock.php,line=239::Avoid using static access to class '\Drupal\Core\Url' in method 'generateButton'. 

Similar also with:

public function getCacheContexts() {
    return Cache::mergeContexts(parent::getCacheContexts(), ['url']);
  }

or Element::children()

cristiroma commented 1 year ago

@tavib47 @stefanbutura - Do you agree with this change?

tv889 commented 1 year ago

Logged ticket https://helpdesk.eaudeweb.ro/issues/15825

Anthelixes commented 1 year ago

PR: @eaudeweb/qa#5