Skip to content

Commit

Permalink
Remove logging
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkyKZ committed Aug 5, 2019
1 parent 2654e91 commit c37ccc4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 165 deletions.
39 changes: 2 additions & 37 deletions libraries/src/Image/Image.php
Expand Up @@ -11,21 +11,13 @@

\defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Log\DelegatingPsrLogger;
use Joomla\CMS\Log\Log;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;

/**
* Class to manipulate an image.
*
* @since 2.5.0
*/
class Image implements LoggerAwareInterface
class Image
{
use LoggerAwareTrait;

/**
* @const integer
* @since 2.5.0
Expand Down Expand Up @@ -123,9 +115,6 @@ public function __construct($source = null)
// @codeCoverageIgnoreEnd
}

// Use DelegatingPsrLogger
$this->logger = Log::createDelegatedLogger();

// Determine which image types are supported by GD, but only once.
if (!isset(static::$formats[IMAGETYPE_JPEG]))
{
Expand Down Expand Up @@ -166,18 +155,6 @@ public function getHandle()
return $this->handle;
}

/**
* Get the logger.
*
* @return LoggerInterface
*
* @since 2.5.0
*/
public function getLogger()
{
return $this->logger;
}

/**
* Method to return a properties object for an image given a filesystem path.
*
Expand Down Expand Up @@ -610,8 +587,6 @@ public function loadFile($path)
// Make sure the image type is supported.
if (empty(static::$formats[IMAGETYPE_GIF]))
{
$this->getLogger()->error('Attempting to load an image of unsupported type GIF.');

throw new \RuntimeException('Attempting to load an image of unsupported type GIF.');
}

Expand All @@ -630,8 +605,6 @@ public function loadFile($path)
// Make sure the image type is supported.
if (empty(static::$formats[IMAGETYPE_JPEG]))
{
$this->getLogger()->error('Attempting to load an image of unsupported type JPG.');

throw new \RuntimeException('Attempting to load an image of unsupported type JPG.');
}

Expand All @@ -650,8 +623,6 @@ public function loadFile($path)
// Make sure the image type is supported.
if (empty(static::$formats[IMAGETYPE_PNG]))
{
$this->getLogger()->error('Attempting to load an image of unsupported type PNG.');

throw new \RuntimeException('Attempting to load an image of unsupported type PNG.');
}

Expand All @@ -668,8 +639,6 @@ public function loadFile($path)
break;

default:
$this->getLogger()->error('Attempting to load an image of unsupported type ' . $properties->mime);

throw new \InvalidArgumentException('Attempting to load an image of unsupported type ' . $properties->mime);
}

Expand Down Expand Up @@ -1001,20 +970,16 @@ protected function getFilterInstance($type)

if (!class_exists($className))
{
$this->getLogger()->error('The ' . ucfirst($type) . ' image filter is not available.');

throw new \RuntimeException('The ' . ucfirst($type) . ' image filter is not available.');
}
}

// Instantiate the filter object.
$instance = new $className($this->getHandle(), $this->logger);
$instance = new $className($this->getHandle());

// Verify that the filter type is valid.
if (!($instance instanceof ImageFilter))
{
$this->getLogger()->error('The ' . ucfirst($type) . ' image filter is not valid.');

throw new \RuntimeException('The ' . ucfirst($type) . ' image filter is not valid.');
}

Expand Down
50 changes: 3 additions & 47 deletions libraries/src/Image/ImageFilter.php
Expand Up @@ -10,21 +10,13 @@

\defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Log\DelegatingPsrLogger;
use Joomla\CMS\Log\Log;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;

/**
* Class to manipulate an image.
*
* @since 2.5.0
*/
abstract class ImageFilter implements LoggerAwareInterface
abstract class ImageFilter
{
use LoggerAwareTrait;

/**
* @var resource The image resource handle.
* @since 2.5.0
Expand All @@ -34,65 +26,29 @@ abstract class ImageFilter implements LoggerAwareInterface
/**
* Class constructor.
*
* @param resource $handle The image resource on which to apply the filter.
* @param LoggerInterface $logger Logger object.
* @param resource $handle The image resource on which to apply the filter.
*
* @since 2.5.0
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function __construct($handle, LoggerInterface $logger = null)
public function __construct($handle)
{
if ($logger === null)
{
{
@trigger_error(
sprintf(
'Not passing a %s instance into the %s constructor is deprecated. As of 5.0, it will be required.',
LoggerInterface::class,
__CLASS__
),
E_USER_DEPRECATED
);

// If a logger hasn't been set, use DelegatingPsrLogger
$logger = Log::createDelegatedLogger();
}
}

$this->logger = $logger;

// Verify that image filter support for PHP is available.
if (!\function_exists('imagefilter'))
{
$this->getLogger()->error('The imagefilter function for PHP is not available.');

throw new \RuntimeException('The imagefilter function for PHP is not available.');
}

// Make sure the file handle is valid.
if (!\is_resource($handle) || (get_resource_type($handle) != 'gd'))
{
$this->getLogger()->error('The image handle is invalid for the image filter.');

throw new \InvalidArgumentException('The image handle is invalid for the image filter.');
}

$this->handle = $handle;
}

/**
* Get the logger.
*
* @return LoggerInterface
*
* @since 2.5.0
*/
public function getLogger()
{
return $this->logger;
}

/**
* Method to apply a filter to an image resource.
*
Expand Down
38 changes: 0 additions & 38 deletions tests/Unit/Libraries/Cms/Image/ImageFilterTest.php
Expand Up @@ -76,42 +76,4 @@ public function testConstructor()
TestHelper::getValue($filter, 'handle')
);
}

/**
* Tests the ImageFilter::getLogger for a DelegatingPsrLogger.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function testGetDelegatingPsrLogger()
{
$logger = $this->instance->getLogger();

$this->assertInstanceOf(
'Joomla\\CMS\\Log\\DelegatingPsrLogger',
$logger,
'When a logger has not been set, an instance of DelegatingPsrLogger should be returned.'
);
}

/**
* Tests the ImageFilter::setLogger and Image::getLogger.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function testSetLogger()
{
$mockLogger = $this->getMockForAbstractClass('Psr\\Log\\AbstractLogger');

$this->instance->setLogger($mockLogger);

$this->assertSame(
$mockLogger,
$this->instance->getLogger(),
'The getLogger method should return the same logger instance that was set via setLogger.'
);
}
}
43 changes: 0 additions & 43 deletions tests/Unit/Libraries/Cms/Image/ImageTest.php
Expand Up @@ -1361,47 +1361,4 @@ public function testDestroy()
// Destroying the image should return boolean true
$this->assertTrue($image->destroy());
}

/**
* Tests the Joomla\CMS\Image\Image::getLogger method
*
* @return void
*
* @covers Joomla\CMS\Image\Image::getLogger
*
* @since __DEPLOY_VERSION__
*/
public function testGetDelegatingPsrLogger()
{
$logger = $this->instance->getLogger();

$this->assertInstanceOf(
'Joomla\\CMS\\Log\\DelegatingPsrLogger',
$logger,
'When a logger has not been set, an instance of DelegatingPsrLogger should be returned.'
);
}

/**
* Tests the Joomla\CMS\Image\Image::setLogger
*
* @return void
*
* @covers Joomla\CMS\Image\Image::setLogger
* @covers Joomla\CMS\Image\Image::getLogger
*
* @since __DEPLOY_VERSION__
*/
public function testSetLogger()
{
$mockLogger = $this->getMockForAbstractClass('Psr\\Log\\AbstractLogger');

$this->instance->setLogger($mockLogger);

$this->assertSame(
$mockLogger,
$this->instance->getLogger(),
'The getLogger method should return the same logger instance that was set via setLogger.'
);
}
}

0 comments on commit c37ccc4

Please sign in to comment.