8
0

Applied fixes from StyleCI

Dieser Commit ist enthalten in:
onigoetz
2016-07-27 15:32:51 -04:00
committet von Stéphane Goetz
Ursprung 1f5521f13a
Commit 029d6cf332
52 geänderte Dateien mit 477 neuen und 424 gelöschten Zeilen

Datei anzeigen

@ -31,7 +31,7 @@ class Api
{
$options = [
'base_uri' => $this->base_url . 'rest/api/',
'auth' => [$this->user, $this->pass]
'auth' => [$this->user, $this->pass],
];
return new Client($options);
@ -68,7 +68,7 @@ class Api
$json = json_decode($body, true);
$message .= ($json != null && array_key_exists('message', $json)) ? $json['message'] : $body;
if ($level == '4' && strpos($message, "page with this title already exists") !== false) {
if ($level == '4' && strpos($message, 'page with this title already exists') !== false) {
return new DuplicateTitleException($message, 0, $e->getPrevious());
}
@ -77,7 +77,7 @@ class Api
public function getPage($id)
{
$url = "content/$id?expand=ancestors,version,body.storage";
$url = "content/$id?expand=ancestors,version,body.storage";
try {
$result = json_decode($this->getClient()->get($url)->getBody(), true);
@ -92,18 +92,18 @@ class Api
}
return [
"id" => $result['id'],
"ancestor_id" => $ancestor_id,
"title" => $result['title'],
"version" => $result['version']['number'],
"content" => $result['body']['storage']['value'],
'id' => $result['id'],
'ancestor_id' => $ancestor_id,
'title' => $result['title'],
'version' => $result['version']['number'],
'content' => $result['body']['storage']['value'],
];
}
/**
* Get a list of pages
*
* @param integer $rootPage
* @param int $rootPage
* @param bool $recursive
* @return array
*/
@ -128,10 +128,10 @@ class Api
foreach ($hierarchy['results'] as $result) {
$pages[$result['title']] = [
"id" => $result['id'],
"title" => $result['title'],
"version" => $result['version']['number'],
"content" => $result['body']['storage']['value'],
'id' => $result['id'],
'title' => $result['title'],
'version' => $result['version']['number'],
'content' => $result['body']['storage']['value'],
];
if ($recursive) {
@ -144,17 +144,16 @@ class Api
// to be a bug in Confluence
$start += $increment;
$url = "$base_url&start=$start";
} while (!empty($hierarchy['results']));
return $pages;
}
/**
* @param integer $parent_id
* @param int $parent_id
* @param string $title
* @param string $content
* @return integer
* @return int
*/
public function createPage($parent_id, $title, $content)
{
@ -162,7 +161,7 @@ class Api
'type' => 'page',
'space' => ['key' => $this->space],
'title' => $title,
'body' => ['storage' => ['value' => $content, 'representation' => 'storage']]
'body' => ['storage' => ['value' => $content, 'representation' => 'storage']],
];
if ($parent_id) {
@ -179,9 +178,9 @@ class Api
}
/**
* @param integer $parent_id
* @param integer $page_id
* @param integer $newVersion
* @param int $parent_id
* @param int $page_id
* @param int $newVersion
* @param string $title
* @param string $content
*/
@ -190,9 +189,9 @@ class Api
$body = [
'type' => 'page',
'space' => ['key' => $this->space],
'version' => ['number' => $newVersion, "minorEdit" => true],
'version' => ['number' => $newVersion, 'minorEdit' => true],
'title' => $title,
'body' => ['storage' => ['value' => $content, 'representation' => 'storage']]
'body' => ['storage' => ['value' => $content, 'representation' => 'storage']],
];
if ($parent_id) {
@ -209,7 +208,7 @@ class Api
/**
* Delete a page
*
* @param integer $page_id
* @param int $page_id
* @return mixed
*/
public function deletePage($page_id)
@ -222,7 +221,7 @@ class Api
}
/**
* @param integer $id
* @param int $id
* @param array $attachment
*/
public function uploadAttachment($id, $attachment)

Datei anzeigen

@ -38,7 +38,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
private function createImageTag($filename, $attributes)
{
$img = "<ac:image";
$img = '<ac:image';
foreach ($attributes as $name => $value) {
$img .= ' ac:' . $name . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"';

Datei anzeigen

@ -8,7 +8,6 @@ use League\CommonMark\HtmlElement;
class FencedCodeRenderer implements BlockRendererInterface
{
protected $supported_languages = [
'actionscript3',
'bash',
@ -32,7 +31,7 @@ class FencedCodeRenderer implements BlockRendererInterface
'ruby',
'scala',
'sql',
'vb'
'vb',
];
protected $known_conversions = ['html' => 'html/xml', 'xml' => 'html/xml', 'js' => 'javascript'];

Datei anzeigen

@ -20,7 +20,7 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
// have the same interface
if (!$inline instanceof Link) {
throw new \RuntimeException(
"Wrong type passed to " . __CLASS__ . "::" . __METHOD__ .
'Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ .
" the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" .
get_class($inline) . "' was provided"
);
@ -34,16 +34,16 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
}
//Internal links
$file = $this->resolveInternalFile(ltrim($url, "!"));
$file = $this->resolveInternalFile(ltrim($url, '!'));
$link_props = [
'ri:content-title' => trim($this->daux['confluence']['prefix']) . " " . $file->getTitle(),
'ri:space-key' => $this->daux['confluence']['space_id']
'ri:content-title' => trim($this->daux['confluence']['prefix']) . ' ' . $file->getTitle(),
'ri:space-key' => $this->daux['confluence']['space_id'],
];
$page = strval(new HtmlElement('ri:page', $link_props, '', true));
$children = $htmlRenderer->renderInlines($inline->children());
if (strpos($children, "<") !== false) {
if (strpos($children, '<') !== false) {
$children = '<ac:link-body>' . $children . '</ac:link-body>';
} else {
$children = '<ac:plain-text-link-body><![CDATA[' . $children . ']]></ac:plain-text-link-body>';

Datei anzeigen

@ -2,5 +2,4 @@
class DuplicateTitleException extends \RuntimeException
{
}

Datei anzeigen

@ -32,7 +32,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
public function getContentTypes()
{
return [
new ContentTypes\Markdown\ContentType($this->daux->getParams())
new ContentTypes\Markdown\ContentType($this->daux->getParams()),
];
}
@ -44,13 +44,13 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
$params = $this->daux->getParams();
$confluence = $params['confluence'];
$this->prefix = trim($confluence['prefix']) . " ";
$this->prefix = trim($confluence['prefix']) . ' ';
$tree = $this->runAction(
"Generating Tree ...",
'Generating Tree ...',
$output,
$width,
function() use ($params) {
function () use ($params) {
$tree = $this->generateRecursive($this->daux->tree, $params);
$tree['title'] = $this->prefix . $params['title'];
@ -58,7 +58,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
}
);
$output->writeln("Start Publishing...");
$output->writeln('Start Publishing...');
$publisher = new Publisher($confluence);
$publisher->output = $output;

Datei anzeigen

@ -23,7 +23,7 @@ class Publisher
protected $previous_title;
/**
* @var integer terminal width
* @var int terminal width
*/
public $width;
@ -48,13 +48,12 @@ class Publisher
try {
return $this->runAction($title, $this->output, $this->width, $closure);
} catch (BadResponseException $e) {
$this->output->writeLn(" <error>" . $e->getMessage() . "</error>");
$this->output->writeLn(' <error>' . $e->getMessage() . '</error>');
}
}
public function publish(array $tree)
{
echo "Finding Root Page...\n";
if (array_key_exists('ancestor_id', $this->confluence)) {
$pages = $this->client->getList($this->confluence['ancestor_id']);
@ -69,14 +68,14 @@ class Publisher
$published = $this->client->getPage($this->confluence['root_id']);
$this->confluence['ancestor_id'] = $published['ancestor_id'];
} else {
throw new \RuntimeException("You must at least specify a `root_id` or `ancestor_id` in your confluence configuration.");
throw new \RuntimeException('You must at least specify a `root_id` or `ancestor_id` in your confluence configuration.');
}
$this->run(
"Getting already published pages...",
function() use (&$published) {
'Getting already published pages...',
function () use (&$published) {
if ($published != null) {
$published['children'] = $this->client->getList($published['id'], true);
}
@ -85,19 +84,19 @@ class Publisher
$published = $this->run(
"Create placeholder pages...\n",
function() use ($tree, $published) {
function () use ($tree, $published) {
return $this->createRecursive($this->confluence['ancestor_id'], $tree, $published);
}
);
$this->output->writeLn("Publishing updates...");
$this->output->writeLn('Publishing updates...');
$published = $this->updateRecursive($this->confluence['ancestor_id'], $tree, $published);
if ($this->shouldDelete()) {
$this->output->writeLn("Deleting obsolete pages...");
$this->output->writeLn('Deleting obsolete pages...');
} else {
$this->output->writeLn("Listing obsolete pages...");
$this->output->writeLn('Listing obsolete pages...');
echo "> The following pages will not be deleted, but just listed for information.\n";
echo "> If you want to delete these pages, you need to set the --delete flag on the command.\n";
}
@ -106,29 +105,29 @@ class Publisher
protected function niceTitle($title)
{
if ($title == "index.html") {
return "Homepage";
if ($title == 'index.html') {
return 'Homepage';
}
return rtrim(strtr($title, ['index.html' => '', '.html' => '']), "/");
return rtrim(strtr($title, ['index.html' => '', '.html' => '']), '/');
}
protected function createPage($parent_id, $entry, $published)
{
echo "- " . $this->niceTitle($entry['file']->getUrl()) . "\n";
echo '- ' . $this->niceTitle($entry['file']->getUrl()) . "\n";
$published['version'] = 1;
$published['title'] = $entry['title'];
$published['id'] = $this->client->createPage($parent_id, $entry['title'], "The content will come very soon !");
$published['id'] = $this->client->createPage($parent_id, $entry['title'], 'The content will come very soon !');
return $published;
}
protected function createPlaceholderPage($parent_id, $entry, $published)
{
echo "- " . $entry['title'] . "\n";
echo '- ' . $entry['title'] . "\n";
$published['version'] = 1;
$published['title'] = $entry['title'];
$published['id'] = $this->client->createPage($parent_id, $entry['title'], "");
$published['id'] = $this->client->createPage($parent_id, $entry['title'], '');
return $published;
}
@ -160,7 +159,7 @@ class Publisher
protected function createRecursive($parent_id, $entry, $published)
{
$callback = function($parent_id, $entry, $published) {
$callback = function ($parent_id, $entry, $published) {
// nothing to do if the ID already exists
if (array_key_exists('id', $published)) {
return $published;
@ -181,7 +180,7 @@ class Publisher
protected function updateRecursive($parent_id, $entry, $published)
{
$callback = function($parent_id, $entry, $published) {
$callback = function ($parent_id, $entry, $published) {
if (array_key_exists('id', $published) && array_key_exists('page', $entry)) {
$this->updatePage($parent_id, $entry, $published);
}
@ -200,23 +199,21 @@ class Publisher
protected function deleteRecursive($published, $prefix = '')
{
foreach($published['children'] as $child) {
foreach ($published['children'] as $child) {
if (array_key_exists('children', $child) && count($child['children'])) {
$this->deleteRecursive($child, $child['title'] . '/');
}
if (!array_key_exists('needed', $child)) {
if ($this->shouldDelete()) {
$this->run(
"- " . $prefix . $child['title'],
function() use ($child) {
'- ' . $prefix . $child['title'],
function () use ($child) {
$this->client->deletePage($child['id']);
}
);
} else {
echo "- " . $prefix . $child['title'] . "\n";
echo '- ' . $prefix . $child['title'] . "\n";
}
}
}
@ -252,7 +249,7 @@ class Publisher
}
//DEBUG
if (getenv("DEBUG") && strtolower(getenv("DEBUG")) != "false") {
if (getenv('DEBUG') && strtolower(getenv('DEBUG')) != 'false') {
$prefix = 'static/export/';
if (!is_dir($prefix)) {
mkdir($prefix, 0777, true);
@ -267,14 +264,14 @@ class Publisher
protected function updatePage($parent_id, $entry, $published)
{
if ($this->previous_title != "Updating") {
$this->previous_title = "Updating";
if ($this->previous_title != 'Updating') {
$this->previous_title = 'Updating';
echo "Updating Pages...\n";
}
$this->run(
"- " . $this->niceTitle($entry['file']->getUrl()),
function() use ($entry, $published, $parent_id) {
'- ' . $this->niceTitle($entry['file']->getUrl()),
function () use ($entry, $published, $parent_id) {
if ($this->shouldUpdate($entry['page'], $published)) {
$this->client->updatePage(
$parent_id,
@ -291,7 +288,7 @@ class Publisher
foreach ($entry['page']->attachments as $attachment) {
$this->run(
" With attachment: $attachment[filename]",
function() use ($published, $attachment) {
function () use ($published, $attachment) {
$this->client->uploadAttachment($published['id'], $attachment);
}
);