for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Helick\Imgix;
use Helick\Contracts\Bootable;
final class Content implements Bootable
{
/**
* Boot the service.
*
* @return void
*/
public static function boot(): void
$self = new static;
add_filter('the_content', [$self, 'parse'], 100);
add_filter
If this is a false-positive, you can also ignore this issue in your code via the ignore-call annotation
ignore-call
/** @scrutinizer ignore-call */
}
* Parse a given content.
* @param string $content
* @return string
public function parse(string $content): string
if (!$images = $this->resolveImages($content)) {
return $content;
if ($attachmentIds = $this->resolveAttachmentIds($images['img_tags'])) {
_prime_post_caches($attachmentIds, false, true);
_prime_post_caches
foreach ($images['img_tags'] as $index => $tag) {
$transform = 'resize';
$transform
$attachmentId = null;
$attachmentId
$fullSizeUrl = null;
$fullSizeUrl
$src = $srcOrig = $images['img_urls'][$index];
$srcOrig
if (!apply_filters('imgix_image_url_processable', true, $src))
apply_filters
if (!/** @scrutinizer ignore-call */ apply_filters('imgix_image_url_processable', true, $src))
continue;
* @return array
private function resolveImages(string $content): array
$pattern = '#(?:<a[^>]+?href=["|\'](?P<link_urls>[^\s]+?)["|\'][^>]*?>\s*)'
. '?(?P<img_tags><img[^>]+?src=["|\'](?P<img_urls>[^\s]+?)["|\'].*?>){1}'
. '(?:\s*</a>)?#is';
if (!preg_match_all($pattern, $content, $images)) {
return [];
$images = array_filter($images, 'is_string', ARRAY_FILTER_USE_KEY);
return $images;
* @param array $tags
private function resolveAttachmentIds(array $tags): array
$attachmentIds = [];
foreach ($tags as $tag) {
if (preg_match('/wp-image-([\d]+)/i', $tag, $matches)) {
$attachmentIds[(int)$matches[1]] = true;
return array_keys($attachmentIds);