GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( e2a30b...fb9ac5 )
by James
22:28 queued 09:33
created

ToAccountNumberEnds::triggered()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 31
rs 9.6666
c 1
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
/**
3
 * ToAccountNumberEnds.php
4
 * Copyright (c) 2019 [email protected]
5
 *
6
 * This file is part of Firefly III (https://github.com/firefly-iii).
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace FireflyIII\TransactionRules\Triggers;
24
25
use FireflyIII\Models\TransactionJournal;
26
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
27
use Log;
28
29
/**
30
 * Class ToAccountNumberEnds.
31
 */
32
final class ToAccountNumberEnds extends AbstractTrigger implements TriggerInterface
33
{
34
    /**
35
     * A trigger is said to "match anything", or match any given transaction,
36
     * when the trigger value is very vague or has no restrictions. Easy examples
37
     * are the "AmountMore"-trigger combined with an amount of 0: any given transaction
38
     * has an amount of more than zero! Other examples are all the "Description"-triggers
39
     * which have hard time handling empty trigger values such as "" or "*" (wild cards).
40
     *
41
     * If the user tries to create such a trigger, this method MUST return true so Firefly III
42
     * can stop the storing / updating the trigger. If the trigger is in any way restrictive
43
     * (even if it will still include 99.9% of the users transactions), this method MUST return
44
     * false.
45
     *
46
     * @param mixed $value
47
     *
48
     * @return bool
49
     */
50
    public static function willMatchEverything($value = null): bool
51
    {
52
        if (null !== $value) {
53
            $res = '' === (string)$value;
54
            if (true === $res) {
55
                Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
56
            }
57
58
            return $res;
59
        }
60
        Log::error(sprintf('Cannot use %s with a null value.', self::class));
61
62
        return true;
63
    }
64
65
    /**
66
     * Returns true when from account ends with X
67
     *
68
     * @param TransactionJournal $journal
69
     *
70
     * @return bool
71
     */
72
    public function triggered(TransactionJournal $journal): bool
73
    {
74
        /** @var JournalRepositoryInterface $repository */
75
        $repository   = app(JournalRepositoryInterface::class);
76
        $dest       = $repository->getDestinationAccount($journal);
77
        $search       = strtolower($this->triggerValue);
78
        $searchLength = strlen($search);
79
80
        $part1 = substr((string)$dest->iban, $searchLength * -1);
81
        $part2 = substr($dest->account_number, $searchLength * -1);
82
83
        if (strtolower($part1) === $search
84
            || strtolower($part2) === $search) {
85
            Log::debug(
86
                sprintf(
87
                    'RuleTrigger %s for journal #%d: "%s" or "%s" ends with "%s", return true.',
88
                    get_class($this), $journal->id, $part1, $part2, $search
89
                )
90
            );
91
92
            return true;
93
        }
94
95
        Log::debug(
96
            sprintf(
97
                'RuleTrigger %s for journal #%d: "%s" and "%s" do not end with "%s", return false.',
98
                get_class($this), $journal->id, $part1, $part2, $search
99
            )
100
        );
101
102
        return false;
103
    }
104
}
105