From 797fd4c07c452dcbbde1776bea51f1820263a0d2 Mon Sep 17 00:00:00 2001 From: Franck Cassedanne Date: Mon, 7 Sep 2015 15:31:07 +0100 Subject: [PATCH] Adds an AbstractBase class traited with PSR3's LoggerAwareTrait (so less code duplication). --- src/JimLind/TiVo/AbstractBase.php | 17 +++++++++++++++++ src/JimLind/TiVo/TiVoFinder.php | 22 +++------------------- src/JimLind/TiVo/VideoDecoder.php | 21 +++------------------ src/JimLind/TiVo/VideoDownloader.php | 21 +++------------------ src/JimLind/TiVo/XmlDownloader.php | 20 ++------------------ 5 files changed, 28 insertions(+), 73 deletions(-) create mode 100644 src/JimLind/TiVo/AbstractBase.php diff --git a/src/JimLind/TiVo/AbstractBase.php b/src/JimLind/TiVo/AbstractBase.php new file mode 100644 index 0000000..f881c8c --- /dev/null +++ b/src/JimLind/TiVo/AbstractBase.php @@ -0,0 +1,17 @@ +logger = new NullLogger(); + } + +} \ No newline at end of file diff --git a/src/JimLind/TiVo/TiVoFinder.php b/src/JimLind/TiVo/TiVoFinder.php index e8c51cf..5bbe6e3 100644 --- a/src/JimLind/TiVo/TiVoFinder.php +++ b/src/JimLind/TiVo/TiVoFinder.php @@ -2,26 +2,20 @@ namespace JimLind\TiVo; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; use Symfony\Component\Process\Process; use Symfony\Component\Process\ProcessBuilder; /** * Service for finding a TiVo on your local network */ -class TiVoFinder +class TiVoFinder extends AbstractBase { + /** * @var ProcessBuilder */ protected $builder; - /** - * @var LoggerInterface - */ - protected $logger; - /** * @param ProcessBuilder $builder The Symfony ProcessBuilder component */ @@ -29,17 +23,7 @@ public function __construct(ProcessBuilder $builder) { $this->builder = $builder; - // Default to the NullLogger - $this->setLogger(new NullLogger()); - } - - /** - * - * @param LoggerInterface $logger - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; + parent::__construct(); } /** diff --git a/src/JimLind/TiVo/VideoDecoder.php b/src/JimLind/TiVo/VideoDecoder.php index 6d82644..816db9b 100644 --- a/src/JimLind/TiVo/VideoDecoder.php +++ b/src/JimLind/TiVo/VideoDecoder.php @@ -2,15 +2,14 @@ namespace JimLind\TiVo; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; use Symfony\Component\Process\ProcessBuilder; /** * Service for decoding encoded TiVo video files */ -class VideoDecoder +class VideoDecoder extends AbstractBase { + /** * @var string */ @@ -21,11 +20,6 @@ class VideoDecoder */ protected $builder; - /** - * @var LoggerInterface - */ - protected $logger; - /** * @param string $mak Your TiVo's Media Access Key * @param ProcessBuilder $builder The Symfony ProcessBuilder component @@ -35,16 +29,7 @@ public function __construct($mak, ProcessBuilder $builder) $this->mak = $mak; $this->builder = $builder; - // Default to the NullLogger - $this->setLogger(new NullLogger()); - } - - /** - * @param LoggerInterface $logger - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; + parent::__construct(); } /** diff --git a/src/JimLind/TiVo/VideoDownloader.php b/src/JimLind/TiVo/VideoDownloader.php index 4abb1c4..46c95fe 100644 --- a/src/JimLind/TiVo/VideoDownloader.php +++ b/src/JimLind/TiVo/VideoDownloader.php @@ -5,14 +5,13 @@ use GuzzleHttp\ClientInterface; use GuzzleHttp\Cookie\CookieJar; use GuzzleHttp\Exception\RequestException; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; /** * Service for downloading video files from a TiVo */ -class VideoDownloader +class VideoDownloader extends AbstractBase { + /** * @var string */ @@ -23,11 +22,6 @@ class VideoDownloader */ protected $guzzle; - /** - * @var LoggerInterface - */ - protected $logger; - /** * @param string $mak Your TiVo's Media Access Key * @param ClientInterface $guzzle A Guzzle Client @@ -37,16 +31,7 @@ public function __construct($mak, ClientInterface $guzzle) $this->mak = $mak; $this->guzzle = $guzzle; - // Default to the NullLogger - $this->setLogger(new NullLogger()); - } - - /** - * @param LoggerInterface $logger - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; + parent::__construct(); } /** diff --git a/src/JimLind/TiVo/XmlDownloader.php b/src/JimLind/TiVo/XmlDownloader.php index c4bfc1b..ef43427 100644 --- a/src/JimLind/TiVo/XmlDownloader.php +++ b/src/JimLind/TiVo/XmlDownloader.php @@ -10,14 +10,12 @@ use GuzzleHttp\Psr7\Uri; use JimLind\TiVo\Characteristic\XmlTrait; use Psr\Http\Message\ResponseInterface; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; use SimpleXMLElement; /** * Service for downloading a list of shows from a TiVo */ -class XmlDownloader +class XmlDownloader extends AbstractBase { use XmlTrait; @@ -36,11 +34,6 @@ class XmlDownloader */ protected $guzzle; - /** - * @var LoggerInterface - */ - protected $logger; - /** * @param string $ip Your TiVo's IP Address * @param string $mak Your TiVo's Media Access Key @@ -56,16 +49,7 @@ public function __construct($ip, $mak, ClientInterface $guzzle) $this->mak = $mak; $this->guzzle = $guzzle; - // Default to the NullLogger - $this->setLogger(new NullLogger()); - } - - /** - * @param LoggerInterface $logger - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; + parent::__construct(); } /**