Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.00% covered (danger)
40.00%
2 / 5
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ConsoleOutputTrait
40.00% covered (danger)
40.00%
2 / 5
50.00% covered (danger)
50.00%
1 / 2
4.94
0.00% covered (danger)
0.00%
0 / 1
 setOutputInterface
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 writeln
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * Console output trait (used to add output support to other classes).
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;
31
32use Symfony\Component\Console\Output\OutputInterface;
33
34/**
35 * Console output trait (used to add output support to other classes).
36 *
37 * @category VuFind
38 * @package  Console
39 * @author   Demian Katz <demian.katz@villanova.edu>
40 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
41 * @link     https://vufind.org/wiki/development Wiki
42 */
43trait ConsoleOutputTrait
44{
45    /**
46     * Output interface.
47     *
48     * @var OutputInterface
49     */
50    protected $outputInterface = null;
51
52    /**
53     * Set the output interface. Implements a fluent interface.
54     *
55     * @param OutputInterface $output Output interface
56     *
57     * @return mixed
58     */
59    public function setOutputInterface(OutputInterface $output)
60    {
61        $this->outputInterface = $output;
62        return $this;
63    }
64
65    /**
66     * Write a line to the output (if available). Implements a fluent interface.
67     *
68     * @param string $output Line to output.
69     *
70     * @return mixed
71     */
72    public function writeln(string $output)
73    {
74        if ($this->outputInterface) {
75            $this->outputInterface->writeln($output);
76        }
77        return $this;
78    }
79}