Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
NormalizeCommand
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 configure
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 * Language command: normalize file or directory.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2020.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Console
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development Wiki
28 */
29
30namespace VuFindConsole\Command\Language;
31
32use Symfony\Component\Console\Attribute\AsCommand;
33use Symfony\Component\Console\Input\InputArgument;
34use Symfony\Component\Console\Input\InputInterface;
35use Symfony\Component\Console\Input\InputOption;
36use Symfony\Component\Console\Output\OutputInterface;
37
38/**
39 * Language command: normalize file or directory.
40 *
41 * @category VuFind
42 * @package  Console
43 * @author   Demian Katz <demian.katz@villanova.edu>
44 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
45 * @link     https://vufind.org/wiki/development Wiki
46 */
47#[AsCommand(
48    name: 'language/normalize',
49    description: 'Language file normalizer'
50)]
51class NormalizeCommand extends AbstractCommand
52{
53    /**
54     * Configure the command.
55     *
56     * @return void
57     */
58    protected function configure()
59    {
60        $this
61            ->setHelp(
62                'Normalizes a file or directory of language strings'
63            )->addOption(
64                'filter',
65                null,
66                InputOption::VALUE_REQUIRED,
67                'file name pattern to use for filtering files to process'
68                . ' (applies only if target is a directory)',
69                '??.ini|??-??.ini'
70            )->addArgument(
71                'target',
72                InputArgument::REQUIRED,
73                'a file or directory to normalize'
74            );
75    }
76
77    /**
78     * Run the command.
79     *
80     * @param InputInterface  $input  Input object
81     * @param OutputInterface $output Output object
82     *
83     * @return int 0 for success
84     */
85    protected function execute(InputInterface $input, OutputInterface $output)
86    {
87        $target = $input->getArgument('target');
88        $filter = $input->getOption('filter');
89
90        if (is_dir($target)) {
91            $this->normalizer->normalizeDirectory($target, $filter);
92        } elseif (is_file($target)) {
93            $this->normalizer->normalizeFile($target);
94        } else {
95            $output->writeln("{$target} does not exist.");
96            return 1;
97        }
98        return 0;
99    }
100}