refactor: action (#2836)

This commit is contained in:
Dag 2022-06-22 18:30:37 +02:00 committed by GitHub
parent fad0dbb6ef
commit ee80f4918e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 51 deletions

View file

@ -21,7 +21,10 @@
* - Returns a responsive web page that automatically checks all whitelisted
* bridges (using JavaScript) if no bridge is specified.
*/
class ConnectivityAction extends ActionAbstract {
class ConnectivityAction implements ActionInterface
{
public $userData = [];
public function execute() {
if(!Debug::isEnabled()) {

View file

@ -11,7 +11,10 @@
* @link https://github.com/rss-bridge/rss-bridge
*/
class DetectAction extends ActionAbstract {
class DetectAction implements ActionInterface
{
public $userData = [];
public function execute() {
$targetURL = $this->userData['url']
or returnClientError('You must specify a url!');

View file

@ -11,7 +11,10 @@
* @link https://github.com/rss-bridge/rss-bridge
*/
class DisplayAction extends ActionAbstract {
class DisplayAction implements ActionInterface
{
public $userData = [];
private function get_return_code($error) {
$returnCode = $error->getCode();
if ($returnCode === 301 || $returnCode === 302) {

View file

@ -11,7 +11,8 @@
* @link https://github.com/rss-bridge/rss-bridge
*/
class ListAction extends ActionAbstract {
class ListAction implements ActionInterface
{
public function execute() {
$list = new StdClass();
$list->bridges = array();

View file

@ -19,7 +19,7 @@ try {
if(array_key_exists('action', $params)) {
$action = $actionFac->create($params['action']);
$action->setUserData($params);
$action->userData = $params;
$action->execute();
} else {
$showInactive = filter_input(INPUT_GET, 'show_inactive', FILTER_VALIDATE_BOOLEAN);

View file

@ -1,33 +0,0 @@
<?php
/**
* This file is part of RSS-Bridge, a PHP project capable of generating RSS and
* Atom feeds for websites that don't have one.
*
* For the full license information, please view the UNLICENSE file distributed
* with this source code.
*
* @package Core
* @license http://unlicense.org/ UNLICENSE
* @link https://github.com/rss-bridge/rss-bridge
*/
/**
* An abstract class for action objects
*/
abstract class ActionAbstract implements ActionInterface {
/**
* Holds the user data.
*
* @var array
*/
protected $userData = null;
/**
* {@inheritdoc}
*
* @param array $userData {@inheritdoc}
*/
public function setUserData($userData) {
$this->userData = $userData;
}
}

View file

@ -15,14 +15,6 @@
* Interface for action objects.
*/
interface ActionInterface {
/**
* Set user data for the action to consume.
*
* @param array $userData An associative array of user data.
* @return void
*/
function setUserData($userData);
/**
* Execute the action.
*

View file

@ -2,7 +2,6 @@
namespace RssBridge\Tests\Actions;
use ActionAbstract;
use ActionInterface;
use PHPUnit\Framework\TestCase;
@ -32,15 +31,15 @@ class ActionImplementationTest extends TestCase {
* @dataProvider dataActionsProvider
*/
public function testVisibleMethods($path) {
$allowedActionAbstract = get_class_methods(ActionAbstract::class);
sort($allowedActionAbstract);
$allowedMethods = get_class_methods(ActionInterface::class);
sort($allowedMethods);
$this->setAction($path);
$methods = get_class_methods($this->obj);
sort($methods);
$this->assertEquals($allowedActionAbstract, $methods);
$this->assertEquals($allowedMethods, $methods);
}
public function dataActionsProvider() {

View file

@ -80,7 +80,6 @@ class ListActionTest extends TestCase {
$actionFac = new ActionFactory();
$action = $actionFac->create('list');
$action->setUserData(array()); /* no user data required */
ob_start();
$action->execute();