Conditions | 7 |
Paths | 33 |
Total Lines | 55 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
86 | public function prepareImageHtml(?Media $image, array $parameters): string |
||
87 | { |
||
88 | if (is_null($image)) { |
||
89 | return "<div class='p-4 bg-yellow-200'>A image with this id has not been found.</div>"; |
||
90 | } |
||
91 | |||
92 | $alt = $image->getCustomProperty('image_description'); |
||
93 | //ray(empty($alt)); |
||
94 | $caption = $image->getCustomProperty('image_caption'); |
||
95 | |||
96 | $width = "w-full sm:" . $parameters['width']; // 100% width mobile, then for bigger devices the one specified |
||
97 | $margin = "mb-6 sm:mb-0 "; |
||
98 | |||
99 | $imagePath = $image->getUrl(); |
||
100 | $thumbnailPath = $image->getUrl('thumb'); |
||
101 | $videoUrl = $image->getCustomProperty('image_video_url'); |
||
102 | |||
103 | $imageLink = ($videoUrl == null) ? $imagePath : $videoUrl; |
||
104 | //$videoPlayIcon = ($videoUrl == null) ? '' : "<i class='far fa-play-circle absolute text-6xl text-white inset-center opacity-80'></i>"; |
||
105 | //$videoPlayIcon = ($videoUrl == null) ? '' : "<svg class='absolute w-14 fill-current text-white inset-center opacity-80' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path d='M371.7 238l-176-107c-15.8-8.8-35.7 2.5-35.7 21v208c0 18.4 19.8 29.8 35.7 21l176-101c16.4-9.1 16.4-32.8 0-42zM504 256C504 119 393 8 256 8S8 119 8 256s111 248 248 248 248-111 248-248zm-448 0c0-110.5 89.5-200 200-200s200 89.5 200 200-89.5 200-200 200S56 366.5 56 256z'/></svg>"; |
||
106 | $videoPlayIcon = ($videoUrl == null) ? '' : "<svg class='absolute h-14 w-14 fill-current inset-center text-primary-500' fill='currentColor' viewBox='0 0 84 84'><circle opacity='0.9' cx='42' cy='42' r='42' fill='white' /><path d='M55.5039 40.3359L37.1094 28.0729C35.7803 27.1869 34 28.1396 34 29.737V54.263C34 55.8604 35.7803 56.8131 37.1094 55.9271L55.5038 43.6641C56.6913 42.8725 56.6913 41.1275 55.5039 40.3359Z' /></svg>"; |
||
107 | |||
108 | switch ($parameters['alignment']) { |
||
109 | case 'right': |
||
110 | $alignment = "float-right"; |
||
111 | $margin .= 'ml-0 sm:ml-3'; |
||
112 | break; |
||
113 | |||
114 | default: |
||
115 | $alignment = "float-left"; |
||
116 | $margin .= 'mr-0 sm:mr-3'; |
||
117 | break; |
||
118 | } |
||
119 | |||
120 | $imageHtml = ""; |
||
121 | $imageHtml .= "<div class='imageSnippet {$width} {$margin} {$alignment} text-center'>"; |
||
122 | $imageHtml .= "<div class='relative inline-block'>"; |
||
123 | $imageHtml .= "<a href='" . $imageLink . "' data-fancybox='images' data-caption='" . $caption . "' alt='" . $alt . "'>"; |
||
124 | $imageHtml .= "<img class='my-0' src='" . $thumbnailPath . "' />"; |
||
125 | $imageHtml .= $videoPlayIcon; |
||
126 | $imageHtml .= "</a>"; |
||
127 | if (is_null($videoUrl)) { |
||
128 | $imageHtml .= "<div class='absolute bottom-0 right-0 p-2 bg-gray-100 opacity-80'>"; |
||
129 | $imageHtml .= "<svg class='w-6 h-6' fill='none' stroke='currentColor' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0zM10 7v3m0 0v3m0-3h3m-3 0H7'></path></svg>"; |
||
130 | $imageHtml .= "</div>"; |
||
131 | } |
||
132 | $imageHtml .= "</div>"; |
||
133 | if (!empty($alt)) { |
||
134 | $imageHtml .= "<div class='text-xs p-2 font-semibold sm:text-left'>"; /*bg-gray-200*/ |
||
135 | $imageHtml .= $alt; |
||
136 | $imageHtml .= "</div>"; |
||
137 | } |
||
138 | $imageHtml .= "</div>"; |
||
139 | |||
140 | return $imageHtml; |
||
141 | } |
||
144 |