mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-25 21:16:47 +00:00
Code clean up.
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search;
|
||||
@@ -56,6 +55,7 @@ class Modifier
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function apply(array $modifier, Transaction $transaction): bool
|
||||
@@ -149,7 +149,7 @@ class Modifier
|
||||
*/
|
||||
public static function stringCompare(string $haystack, string $needle): bool
|
||||
{
|
||||
$res = !(strpos(strtolower($haystack), strtolower($needle)) === false);
|
||||
$res = !(false === strpos(strtolower($haystack), strtolower($needle)));
|
||||
Log::debug(sprintf('"%s" is in "%s"? %s', $needle, $haystack, var_export($res, true)));
|
||||
|
||||
return $res;
|
||||
@@ -164,11 +164,11 @@ class Modifier
|
||||
private static function budget(Transaction $transaction, string $search): bool
|
||||
{
|
||||
$journalBudget = '';
|
||||
if (!is_null($transaction->transaction_journal_budget_name)) {
|
||||
if (null !== $transaction->transaction_journal_budget_name) {
|
||||
$journalBudget = Steam::decrypt(intval($transaction->transaction_journal_budget_encrypted), $transaction->transaction_journal_budget_name);
|
||||
}
|
||||
$transactionBudget = '';
|
||||
if (!is_null($transaction->transaction_budget_name)) {
|
||||
if (null !== $transaction->transaction_budget_name) {
|
||||
$journalBudget = Steam::decrypt(intval($transaction->transaction_budget_encrypted), $transaction->transaction_budget_name);
|
||||
}
|
||||
|
||||
@@ -184,11 +184,11 @@ class Modifier
|
||||
private static function category(Transaction $transaction, string $search): bool
|
||||
{
|
||||
$journalCategory = '';
|
||||
if (!is_null($transaction->transaction_journal_category_name)) {
|
||||
if (null !== $transaction->transaction_journal_category_name) {
|
||||
$journalCategory = Steam::decrypt(intval($transaction->transaction_journal_category_encrypted), $transaction->transaction_journal_category_name);
|
||||
}
|
||||
$transactionCategory = '';
|
||||
if (!is_null($transaction->transaction_category_name)) {
|
||||
if (null !== $transaction->transaction_category_name) {
|
||||
$journalCategory = Steam::decrypt(intval($transaction->transaction_category_encrypted), $transaction->transaction_category_name);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search;
|
||||
@@ -33,9 +32,7 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class Search
|
||||
*
|
||||
* @package FireflyIII\Search
|
||||
* Class Search.
|
||||
*/
|
||||
class Search implements SearchInterface
|
||||
{
|
||||
@@ -43,13 +40,13 @@ class Search implements SearchInterface
|
||||
private $limit = 100;
|
||||
/** @var Collection */
|
||||
private $modifiers;
|
||||
/** @var string */
|
||||
/** @var string */
|
||||
private $originalQuery = '';
|
||||
/** @var User */
|
||||
private $user;
|
||||
/** @var array */
|
||||
private $validModifiers = [];
|
||||
/** @var array */
|
||||
/** @var array */
|
||||
private $words = [];
|
||||
|
||||
/**
|
||||
@@ -67,7 +64,7 @@ class Search implements SearchInterface
|
||||
public function getWordsAsString(): string
|
||||
{
|
||||
$string = join(' ', $this->words);
|
||||
if (strlen($string) === 0) {
|
||||
if (0 === strlen($string)) {
|
||||
return is_string($this->originalQuery) ? $this->originalQuery : '';
|
||||
}
|
||||
|
||||
@@ -150,7 +147,7 @@ class Search implements SearchInterface
|
||||
Log::debug(sprintf('Total count is now %d', $result->count()));
|
||||
|
||||
// Update counters
|
||||
$page++;
|
||||
++$page;
|
||||
$processed += count($set);
|
||||
|
||||
Log::debug(sprintf('Page is now %d, processed is %d', $page, $processed));
|
||||
@@ -235,7 +232,6 @@ class Search implements SearchInterface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $collector;
|
||||
}
|
||||
|
||||
@@ -245,12 +241,12 @@ class Search implements SearchInterface
|
||||
private function extractModifier(string $string)
|
||||
{
|
||||
$parts = explode(':', $string);
|
||||
if (count($parts) === 2 && strlen(trim(strval($parts[0]))) > 0 && strlen(trim(strval($parts[1])))) {
|
||||
if (2 === count($parts) && strlen(trim(strval($parts[0]))) > 0 && strlen(trim(strval($parts[1])))) {
|
||||
$type = trim(strval($parts[0]));
|
||||
$value = trim(strval($parts[1]));
|
||||
if (in_array($type, $this->validModifiers)) {
|
||||
// filter for valid type
|
||||
$this->modifiers->push(['type' => $type, 'value' => $value,]);
|
||||
$this->modifiers->push(['type' => $type, 'value' => $value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,6 +255,7 @@ class Search implements SearchInterface
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function matchModifiers(Transaction $transaction): bool
|
||||
@@ -278,7 +275,7 @@ class Search implements SearchInterface
|
||||
// then a for-each and a switch for every possible other thingie.
|
||||
foreach ($this->modifiers as $modifier) {
|
||||
$res = Modifier::apply($modifier, $transaction);
|
||||
if ($res === false) {
|
||||
if (false === $res) {
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -294,11 +291,11 @@ class Search implements SearchInterface
|
||||
*/
|
||||
private function strposArray(string $haystack, array $needle)
|
||||
{
|
||||
if (strlen($haystack) === 0) {
|
||||
if (0 === strlen($haystack)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($needle as $what) {
|
||||
if (stripos($haystack, $what) !== false) {
|
||||
if (false !== stripos($haystack, $what)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search;
|
||||
@@ -27,9 +26,7 @@ use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface SearchInterface
|
||||
*
|
||||
* @package FireflyIII\Support\Search
|
||||
* Interface SearchInterface.
|
||||
*/
|
||||
interface SearchInterface
|
||||
{
|
||||
@@ -48,7 +45,6 @@ interface SearchInterface
|
||||
*/
|
||||
public function parseQuery(string $query);
|
||||
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user