for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace SilverStripe\Forms\HtmlEditor;
use Embed\Adapters\Adapter;
use Embed\Embed;
use ShortcodeHandler;
/**
* Class EmbedShortcodeProvider
*
* Provider for the [embed] shortcode tag used by the embedding service
* in the HTML Editor field.
* Provides the html needed for the frontend and the editor field itself.
* @package SilverStripe\Forms\HtmlEditor
*/
class EmbedShortcodeProvider implements ShortcodeHandler
{
* Gets the list of shortcodes provided by this handler
* @return mixed
public static function get_shortcodes()
return array('embed');
}
* Embed shortcode parser from Oembed. This is a temporary workaround.
* Oembed class has been replaced with the Embed external service.
* @param $arguments
* @param $content
* @param $parser
* @param $shortcode
* @param array $extra
* @return string
public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = array()) {
$embed = Embed::create($content, $arguments);
if($embed && $embed instanceof \Embed\Adapters\Adapter) {
return self::embedForTemplate($embed);
} else {
return '<a href="' . $content . '">' . $content . '</a>';
* @param Adapter $embed
public static function embedForTemplate($embed)
switch ($embed->type) {
case 'video':
case 'rich':
if ($embed->extraClass) {
return "<div class='media $embed->extraClass'>$embed->code</div>";
return "<div class='media'>$embed->code</div>";
break;
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.
return
die
exit
function fx() { try { doSomething(); return true; } catch (\Exception $e) { return false; } return false; }
In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.
return false
case 'link':
return '<a class="' . $embed->extraClass . '" href="' . $embed->origin . '">' . $embed->title . '</a>';
break
The break statement is not necessary if it is preceded for example by a return statement:
switch ($x) { case 1: return 'foo'; break; // This break is not necessary and can be left off. }
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.
case 'photo':
return "<img src='$embed->url' width='$embed->width' height='$embed->height' class='$embed->extraClass' />";
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.