diff --git a/app/Actors/ConfigConverter.php b/app/Actors/ConfigConverter.php deleted file mode 100644 index 06db3c1..0000000 --- a/app/Actors/ConfigConverter.php +++ /dev/null @@ -1,72 +0,0 @@ -config = $config; - $this->converter = $converter; - } - - public function convert(bool $force = false) - { - $fakeTransaction = new IngTransaction(); - $fakeTransaction->notes = new IngTransaction\Notes('Fake notes ;)'); - - $replacements = [ - "'\n" => "\n", - "':" => ':', - " '" => ' ', - "''" => "'", - ]; - - foreach ($this->config->get('csv2qif') as $ruleSetName => $ruleSet) { - foreach ($ruleSet['matchers'] as $matcherName => $matcher) { - ['all of' => $converted] = $this->converter->allOf($fakeTransaction, ...$matcher['rules']); - - $ruleSet['matchers'][$matcherName]['rules'] = $converted; - } - - $filename = sprintf(RuleSetConfig::FILENAME_FORMAT, $ruleSetName); - $yaml = Yaml::dump($ruleSet, 99, 4, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE); - - foreach ($replacements as $needle => $replacement) { - $yaml = str_replace($needle, $replacement, $yaml); - } - - if (!$force && file_exists($filename)) { - throw new \Exception("File {$filename} already exists, run with --force to override!"); - } - - if (file_exists($filename) && !is_writable($filename)) { - throw new \Exception("File {$filename} is not writable, make sure to run with the right permissions!"); - } - - if (!file_exists($filename) && !is_writable('.')) { - throw new \Exception('Project root is not writable, make sure to run with the right permissions!'); - } - - file_put_contents($filename, $yaml); - } - } -} diff --git a/app/Command/Config.php b/app/Command/Config.php deleted file mode 100644 index f2fe79f..0000000 --- a/app/Command/Config.php +++ /dev/null @@ -1,32 +0,0 @@ -addOption(self::OPT_FORCE); - - $this->converter = $converter; - } - - public function run(): void - { - $force = (bool) $this->parameter->getOption(self::OPT_FORCE); - - $this->converter->convert($force); - } -} diff --git a/app/Config/.gitignore b/app/Config/.gitignore deleted file mode 100644 index 68d9027..0000000 --- a/app/Config/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -* -!.gitignore -!App.php -!Example.php diff --git a/app/Config/App.php b/app/Config/App.php index 58ddbb0..e290b57 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -2,27 +2,22 @@ namespace Config; -use Csv2Qif\Command\Config; use Csv2Qif\Command\Convert; use Csv2Qif\Command\Ui; use Csv2Qif\Command\Validate; -use Parable\Framework\Interfaces\Config as ParableConfig; +use Parable\Framework\Interfaces\Config; -class App implements ParableConfig +class App implements Config { public function get(): array { return [ 'parable' => [ 'commands' => [ - Config::class, Convert::class, Ui::class, Validate::class, ], - 'configs' => [ - Example::class, - ], ], ]; } diff --git a/app/Config/Example.php b/app/Config/Example.php deleted file mode 100644 index 9f85f17..0000000 --- a/app/Config/Example.php +++ /dev/null @@ -1,122 +0,0 @@ - [ - 'fallback' => true, // default - 'matchers' => [ - 'Joint Account In' => [ - 'transfer' => 'Income:Joint Account', - 'description' => ['getNoteDescription'], // default - 'rules' => [ - ['equals', 'transfer', ''], - ['greaterThan', 'amount', 0], - ], - ], - 'Joint Account Ex' => [ - 'transfer' => 'Expenses:Joint Account', - 'rules' => [ - ['equals', 'transfer', ''], - ['lessThan', 'amount', 0], - ], - ], - 'Father\'s House Ministries' => [ - 'transfer' => 'Gifts:Father\'s House Ministries', - 'rules' => [ - ['contains', 'description', 'Fathers House.Ministries'], - ], - ], - 'Go and Tell Gifts' => [ - 'transfer' => 'Gifts:Go and Tell', - 'rules' => [ - ['contains', 'description', 'Go and Tell'], - ['equals', 'notes->authorizationId', '12345'], - ], - ], - 'ING Costs' => [ - 'transfer' => 'Expenses:ING', - 'rules' => [ - ['contains', 'description', 'Kosten'], - [ - 'oneOf', - ['contains', 'notes->description', 'ING Bank'], - [ - 'allOf', - ['isEmpty', 'notes->description'], - ['contains', 'notes->source', 'ING Bank'], - ], - ], - ], - ], - 'Specsavers Contacts' => [ - 'transfer' => 'Expenses:Specsavers:Contacts', - 'rules' => [ - ['contains', 'description', 'Specsavers'], - ['not', 'isEmpty', 'notes->authorizationId'], - ], - ], - 'Specsavers Glasses' => [ - 'transfer' => 'Expenses:Specsavers:Glasses', - 'rules' => [ - ['contains', 'description', 'Specsavers'], - ['isEmpty', 'notes->authorizationId'], - ], - ], - 'Oranje Spaarrekening Deposit' => [ - 'transfer' => 'Assets:Bank:Savings', - 'description' => 'Deposit', - 'rules' => [ - ['equals', 'account', ''], - ['equals', 'notes->source', 'Naar Oranje Spaarrekening '], - ], - ], - 'Oranje Spaarrekening Withdrawal' => [ - 'transfer' => 'Assets:Bank:Savings', - 'description' => 'Withdrawal', - 'rules' => [ - ['equals', 'account', ''], - ['equals', 'notes->source', 'Van Oranje Spaarrekening '], - ], - ], - ], - ], - // This ruleset is an example for the joint account referenced above, if you manage that separately. - 'csv2qif.example-joint' => [ - 'matchers' => [ - 'Personal Account In' => [ - 'transfer' => 'Income:Personal Account', - 'rules' => [ - ['equals', 'transfer', ''], - ['greaterThan', 'amount', 0], - ], - ], - 'Personal Account Ex' => [ - 'transfer' => 'Expenses:Personal Account', - 'rules' => [ - ['equals', 'transfer', ''], - ['lessThan', 'amount', 0], - ], - ], - 'Utilities' => [ - 'transfer' => 'Expenses:Utilities', - 'rules' => [ - ['isEmpty', 'description'], - ['not', 'equals', 'transfer', 'poop n stuff'], - ], - ], - ], - ], - ]; - } -}