class ExampleService in Coder 8.3.x
Same name and namespace in other branches
- 8.3 tests/DrupalPractice/Objects/drupal8/ExampleService.php \Drupal\testmodule\ExampleService
- 8.2 coder_sniffer/DrupalPractice/Test/Objects/src/ExampleService.php \Drupal\testmodule\ExampleService
Some service.
Hierarchy
- class \Drupal\testmodule\ExampleService
Expanded class hierarchy of ExampleService
1 string reference to 'ExampleService'
- testmodule.services.yml in tests/
DrupalPractice/ Objects/ testmodule.services.yml - tests/DrupalPractice/Objects/testmodule.services.yml
1 service uses ExampleService
- testmodule.example in tests/
DrupalPractice/ Objects/ testmodule.services.yml - Drupal\testmodule\ExampleService
File
- tests/
DrupalPractice/ Objects/ drupal8/ ExampleService.php, line 10
Namespace
Drupal\testmoduleView source
class ExampleService {
/**
* Using \Drupal here but it should be injected instead.
*/
public function test() {
return \Drupal::configFactory();
}
/**
* Loading nodes should be done from an injected service.
*/
public function test2() {
return Node::load(1);
}
/**
* Global function should not be used, we should use an injected service.
*/
public function test3() {
return format_date(time());
}
/**
* t() should not be used, instead we should use the StringTranslationTrait.
*/
public function test4() {
return t('Test');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExampleService:: |
public | function | Using \Drupal here but it should be injected instead. | |
ExampleService:: |
public | function | Loading nodes should be done from an injected service. | |
ExampleService:: |
public | function | Global function should not be used, we should use an injected service. | |
ExampleService:: |
public | function | t() should not be used, instead we should use the StringTranslationTrait. |