for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Install GitHub App
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <[email protected]>
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use finfo;
use SplFileInfo;
use function is_file;
use function is_string;
use function mb_strpos;
/**
* Validates if the file is a valid image by checking its MIME type.
* @author Danilo Benevides <[email protected]>
* @author Guilherme Siani <[email protected]>
* @author Henrique Moody <[email protected]>
final class Image extends AbstractRule
{
* @var finfo
private $fileInfo;
* Initializes the rule.
* @param finfo|null $fileInfo
public function __construct(finfo $fileInfo = null)
$this->fileInfo = $fileInfo ?: new finfo(FILEINFO_MIME_TYPE);
}
* {@inheritdoc}
public function validate($input): bool
if ($input instanceof SplFileInfo) {
return $this->validate($input->getPathname());
if (!is_string($input)) {
return false;
if (!is_file($input)) {
return 0 === mb_strpos($this->fileInfo->file($input), 'image/');