T
T
thorii2016-09-14 14:17:51
PHP
thorii, 2016-09-14 14:17:51

How critical is duplication of code in several lines?

Let's say I have a piece of code (semantic duplication, that is, they implement the same thing in meaning)

$query = (new QueryChain())->select('*')
    ->from($this->store())
    ->where([$pk => ":$pk"])
    ->limit(1)
    ->build(); //Естественно этот кусок индивидуален для каждого запроса
$statement->bindValue($pk, $key); //И это тоже индивидуально!
$statement = $this->connection->prepare($query);

Or is it worth having a separate method like prepareQuery($query, $params) //@return PDO Statement
UPD. Lines are duplicated in a maximum of 2-3 methods.
I understand that you can get confused later, but I have already developed the habit of generating phpDOC for each method.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2016-09-14
@thorii

Honestly? I wouldn't want to bundle this into a separate method. Save money on matches.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question