| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Plugin | Php Inspections ​(EA Extended)​, v3.0.13 |
| Language level | e.g. PHP 7.1 |

public function saveData(array $data): bool
{
$connection = $this->getConnection();
$connection->beginTransaction();
// should return true when save data and commit or false
return ($this->saveObject($data) && $connection->commit()) or ($connection->rollBack() && false);
}
PhpStorm 2019.1.1
Php Inspections ​(EA Extended)​, v3.0.13
Build #PS-191.6707.66, built on April 17, 2019
JRE: 1.8.0_202-release-1483-b44 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Hello, @almost-online Is this a problem?
You should not write true or false in the source code because this makes no sense.
@almost-online: can you share more similar samples please?
PS: Were other reported cases correctly spotted?
I somehow agree with @funivan , but would like to better understand your case as well.
this is not problem but I should to rewrite the code to this (equal) one:
public function saveData(array $data): bool
{
$connection = $this->getConnection();
$connection->beginTransaction();
// should return true when save data and commit or false
if ($this->saveObject($data)) {
return $connection->commit();
}
$connection->rollBack();
return false;
}
Ok, then one more question: was the refactoring a good thing in your case?
in case ($connection->rollBack() && false) - the $connection->rollBack() will return true when rolled back the transaction but I shoudl always return false in case I`ve not save an object
Ok, then one more question: was the refactoring a good thing in your case?
probably this refactor will become more readable but the code become longer
Ok, let then introduce a new inspection setting to report/not to report the hard-coded booleans
anyway, this is not urgent
Refactored code seems to be better for me ;) Easy to read and maintain. IMHO
Implemented the new settings!
Most helpful comment
Refactored code seems to be better for me ;) Easy to read and maintain. IMHO