Skip to content
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.

Commit

Permalink
Removed hard-coded time cursor and improved code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Degryse committed Dec 28, 2014
1 parent d5cbd63 commit 243d289
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Module/NewPostModule/NewPostModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(ConnectionManager $connectionManager)
{
parent::__construct($connectionManager);

$this->timeCursor = 1419745310; //time();
$this->timeCursor = time();
}

/**
Expand Down Expand Up @@ -126,7 +126,8 @@ private function gistifyMessage($entity)
'Content-Length' => strlen($data)
];

$request = new CURLRequest('https://api.github.com', '/gists', 'POST', null, $data, false, $headers);
$baseUrl = 'https://api.github.com';
$request = new CURLRequest($baseUrl, '/gists', 'POST', null, $data, false, $headers);
$response = json_decode($request->execute());

return $response->html_url;
Expand All @@ -151,25 +152,30 @@ private function parseEntity(Connection $connection, $post)
libxml_clear_errors();

$forms = $dom->getElementsByTagName('form');
$commentForm = null;

foreach ($forms as $form) {
if (strtoupper($form->getAttribute('method')) == 'POST') {
$commentActionUrl = $form->getAttribute('action');
$inputElements = $form->getElementsByTagName('input');
$commentForm = $form;
}
}

$commentInputData = [ 'submit' => 'Post' ];
if ($commentForm == null) {
throw new \Exception("NewPostEntity was not created because the comment form could not be found");
}

foreach ($inputElements as $input) {
if ($input->getAttribute('type') != 'submit') {
$commentInputData[$input->getAttribute('name')] = $input->getAttribute('value');
}
}
$commentActionUrl = $form->getAttribute('action');
$inputElements = $form->getElementsByTagName('input');

$commentInputData = [ 'submit' => 'Post' ];

return new NewPostEntity($postId, $author, $message, $commentActionUrl, $commentInputData);
foreach ($inputElements as $input) {
if ($input->getAttribute('type') != 'submit') {
$commentInputData[$input->getAttribute('name')] = $input->getAttribute('value');
}
}

return null;
return new NewPostEntity($postId, $author, $message, $commentActionUrl, $commentInputData);
}

/**
Expand Down

0 comments on commit 243d289

Please # to comment.