Z
Z
zeuss562017-03-22 18:53:08
PHP
zeuss56, 2017-03-22 18:53:08

Are there code analyzers/refactorers to remove redundancy (in PHP, but other languages ​​are interesting)?

The most minimal example of getting rid of redundancy:

function someFunc($arg = null) {
  if (!empty($arg))
    return anyValue;
  else
    return anotherValue;
}

turns into:
function someFunc($arg = null) {
  if (!empty($arg))
    return anyValue;
  return anotherValue;
}

There are many other situations besides this, and automatic solutions for fixing these kinds of errors should not be used all the time, but can help when refactoring old code.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max, 2017-03-22
@7workers

it actually turns into this:

function someFunc($arg = null) {
 return !empty($arg) ? $anyValue : $anotherValue;
}

if, in essence, such things are done by the compiler, and the code does not always need to be "optimized" to the point of being impossible. Some really monstrous things will be highlighted by a good IDE, such as PhpStorm.

A
Alexander Pozharsky, 2017-03-22
@alex4321

phplint or similar linter for php, perhaps?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question