Showing 9 of 9 total issues
Avoid using short method names like StringTranslatingTrait::__(). The configured minimum method name length is 3. Open
protected function __($string, $args = array(), $context = null)
{
$string = $this->_translate($string, $context);
array_unshift($args, $string);
$result = call_user_func_array('sprintf', $args);
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Avoid unused parameters such as '$context'. Open
protected function _translate($string, $context = null)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid assigning values to variables in if clauses and the like (line '26', column '16'). Open
protected function _translate($string, $context = null)
{
if (!(($translator = $this->_getTranslator()) instanceof StringTranslatorInterface)) {
return $string;
}
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method _getTranslator is not named in camelCase. Open
abstract protected function _getTranslator();
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _translate is not named in camelCase. Open
protected function _translate($string, $context = null)
{
return $string;
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _setTranslator is not named in camelCase. Open
protected function _setTranslator($translator)
{
if (!(is_null($translator) || $translator instanceof StringTranslatorInterface)) {
throw new InvalidArgumentException('Invalid translator');
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method __ is not named in camelCase. Open
protected function __($string, $args = array(), $context = null)
{
$string = $this->_translate($string, $context);
array_unshift($args, $string);
$result = call_user_func_array('sprintf', $args);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getTranslator is not named in camelCase. Open
protected function _getTranslator()
{
return $this->translator;
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _translate is not named in camelCase. Open
protected function _translate($string, $context = null)
{
if (!(($translator = $this->_getTranslator()) instanceof StringTranslatorInterface)) {
return $string;
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}