Skip to content

Commit 7820774

Browse files
Oliver Kleeoliverklee
Oliver Klee
authored andcommitted
[CLEANUP] Add and fix the PhpDoc for the REST API V2
This makes the code easier to follow in IDEs, and also easier to read and understand. Also fix some static/non-static mismatches and add public visibility where it is missing.
1 parent 16d940b commit 7820774

13 files changed

+310
-150
lines changed

plugins/restapi2/call.php

+3
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@
6161
}
6262

6363
// Get necessary objects from container
64+
/** @var \Rapi\Call $call */
6465
$call = $container->get( 'Call' );
66+
/** @var \Rapi\Response $response */
6567
$response = $container->get( 'Response' );
6668

6769
// Check if you are calling loginHandler, if you aren't, it checks for a token to see if you are logged in
6870
if($_GET['className'] !== "loginHandler"){
6971

72+
/** @var \Rapi\Admin $admin */
7073
$admin = $container->get( 'Admin' );
7174

7275
if(isset($_POST['token'])){

plugins/restapi2/lib/Admin.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,35 @@
66
* Class for account related commands
77
*/
88
class Admin {
9-
10-
// Response object
9+
/**
10+
* @var Response
11+
*/
1112
protected $response;
1213
/**
13-
* @var AdminModel
14+
* @var \phpListAdminAuthentication
1415
*/
1516
private $admin;
1617

1718
/**
1819
* Admin constructor.
1920
* @param Response $response
20-
* @param AdminModel $adminModel
21+
* @param \phpListAdminAuthentication $admin
2122
*/
22-
public function __construct(Response $response, \phpList\Admin $admin )
23+
public function __construct(Response $response, \phpListAdminAuthentication $admin)
2324
{
2425
$this->response = $response;
2526
$this->admin = $admin;
2627
}
2728

2829
/**
2930
* Function to call for login.
31+
*
3032
* @todo: Finish implementing this method
31-
* [*login] {string} loginname as an admin to phpList
32-
* [*password] {string} the password
33-
* @return boolean
34-
* @throws \Exception
33+
*
34+
* @param string $password login name as an admin to phpList
35+
* @param string $username the password
36+
*
37+
* @return bool
3538
*/
3639
public function login( $password, $username )
3740
{
@@ -41,10 +44,13 @@ public function login( $password, $username )
4144
$this->admin->setLoginToken($data['admin']->id);
4245
return $this->admin->getLoginToken($data['admin']->id);
4346
}
47+
48+
return false;
4449
}
4550

4651
/**
47-
* @param $token string
52+
* @param string $token
53+
*
4854
* @return bool
4955
*/
5056
public function isLoggedIn( $token ){
@@ -55,7 +61,6 @@ public function isLoggedIn( $token ){
5561
* Processes the Message Queue in phpList.
5662
* @todo: Finish implementing this method
5763
* @note: Perhaps this is done via CRON or manually through the admin interface?
58-
* [*login] {string} loginname as an admin to phpList
5964
*/
6065
public function processQueue()
6166
{

plugins/restapi2/lib/Call.php

+35-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Rapi;
44

5+
use phpList\Entity\SubscriberEntity;
6+
use Rapi\Handler\ListHandler;
7+
use Rapi\Handler\LoginHandler;
8+
use Rapi\Handler\SubscriberHandler;
9+
510
/**
611
* Class to handle API call functionality and execution
712
* @note This class is ignorant of call output and forwards it transparently --
@@ -11,24 +16,30 @@ class Call {
1116

1217
/**
1318
* Constructor requires all classes that may handle calls as arguments
19+
*
1420
* @note To add support for an API call, add it's parent class to arguments
15-
* @param Lists $lists
16-
* @param SubscriberHandler $subscriberHandler
21+
* @param Handler\ListHandler $listHandler
22+
* @param Handler\SubscriberHandler|SubscriberHandler $subscriberHandler
23+
* @param Handler\LoginHandler $loginHandler
24+
* @internal param Lists $lists
1725
*/
1826
public function __construct(
19-
\Rapi\Handler\ListHandler $listHandler
20-
, \Rapi\Handler\SubscriberHandler $subscriberHandler
21-
, \Rapi\Handler\LoginHandler $loginHandler
27+
ListHandler $listHandler,
28+
SubscriberHandler $subscriberHandler,
29+
LoginHandler $loginHandler
2230
)
2331
{
2432
$this->listHandler = $listHandler;
2533
$this->subscriberHandler = $subscriberHandler;
2634
$this->loginHandler = $loginHandler;
2735
}
36+
2837
/**
2938
* Validate a requested call by checking characters and syntax
39+
*
3040
* @param string $className Name of class to validate
3141
* @param string $method Name of method to validate
42+
*
3243
* @return bool $result
3344
*/
3445
public function validateCall( $className, $method )
@@ -55,7 +66,10 @@ public function validateCall( $className, $method )
5566

5667
/**
5768
* Get API call configuraiton whitelist
69+
*
5870
* @param string $whitelistPath Path to whitelist configuration file
71+
*
72+
* @return mixed
5973
*/
6074
public function getWhitelistConfig( $whitelistPath = NULL )
6175
{
@@ -83,7 +97,11 @@ public function getWhitelistConfig( $whitelistPath = NULL )
8397

8498
/**
8599
* Check if the supplied class name is permitted by the whitelist
100+
*
86101
* @param string $className Class name to check
102+
* @param string $method
103+
*
104+
* @return bool
87105
*/
88106
public function isCallWhitelisted( $className, $method )
89107
{
@@ -107,10 +125,12 @@ public function isCallWhitelisted( $className, $method )
107125

108126
/**
109127
* Validate an API call and execute the requested method on handler object
128+
*
110129
* @param string $className to execute method on
111130
* @param string $method name of method to execute
112131
* @param array $argumentsArray arguments to pass to method
113-
* @return \phpList\Entity\SubscriberEntity Data object
132+
*
133+
* @return SubscriberEntity Data object
114134
*/
115135
public function doCall( $className, $method, array $argumentsArray )
116136
{
@@ -143,7 +163,10 @@ public function doCall( $className, $method, array $argumentsArray )
143163

144164
/**
145165
* Format raw user-privded API call parameters for passing to handler object
166+
*
146167
* @param array $argumentsArray user-supplied API call parameters
168+
*
169+
* @return array
147170
*/
148171
public function formatParams( array $argumentsArray ) {
149172

@@ -159,7 +182,10 @@ public function formatParams( array $argumentsArray ) {
159182

160183
/**
161184
* Convert any var type to an array suitable for passing to a response
185+
*
162186
* @param mixed $callResult Returned value of an executed API call
187+
*
188+
* @return array|mixed
163189
*/
164190
public function callResultToArray( $callResult )
165191
{
@@ -191,10 +217,12 @@ public function callResultToArray( $callResult )
191217
* This function converts an object into an associative array by iterating
192218
* over its public properties. Because this function uses the foreach
193219
* construct, Iterators are respected. It also works on arrays of objects.
220+
*
194221
* @param object $object The object to be converted
222+
*
195223
* @return array $result Converted object
196224
*/
197-
function objectToArray( $object )
225+
public function objectToArray( $object )
198226
{
199227
$result = array();
200228
$references = array();

plugins/restapi2/lib/Campaigns.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
*/
1111
class Messages
1212
{
13+
/**
14+
* @param int $id
15+
*/
1316
public static function messageGet($id = 0)
1417
{
1518
if ($id == 0) {
1619
$id = $_REQUEST['id'];
1720
}
1821
Common::select('Message', 'SELECT * FROM '.$GLOBALS['table_prefix'].'message WHERE id='.$id.';', true);
1922
}
20-
23+
2124
public static function messagesCount()
2225
{
2326
Common::select('Messages', 'SELECT count(id) as total FROM '.$GLOBALS['table_prefix'].'message',true);
@@ -31,7 +34,7 @@ public static function messagesGet()
3134

3235
/**
3336
* Add a new campaign.
34-
*
37+
*
3538
* <p><strong>Parameters:</strong><br/>
3639
* [*subject] {string} <br/>
3740
* [*fromfield] {string} <br/>
@@ -80,7 +83,7 @@ public static function messageAdd()
8083

8184
/**
8285
* Update existing message/campaign.
83-
*
86+
*
8487
* <p><strong>Parameters:</strong><br/>
8588
* [*id] {integer} <br/>
8689
* [*subject] {string} <br/>
@@ -99,6 +102,8 @@ public static function messageAdd()
99102
* <p><strong>Returns:</strong><br/>
100103
* The message added.
101104
* </p>
105+
*
106+
* @param int $id
102107
*/
103108
public static function messageUpdate($id = 0)
104109
{

plugins/restapi2/lib/Common.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@
33
namespace Rapi;
44

55
class Common {
6-
7-
// Extended pdo object
6+
/**
7+
* @var PdoEx
8+
*/
89
protected $pdoEx;
910

11+
/**
12+
* Common constructor.
13+
*
14+
* @param PdoEx $pdoEx
15+
* @param Response $response
16+
*/
1017
public function __construct( PdoEx $pdoEx, Response $response )
1118
{
1219
$this->pdoEx = $pdoEx;
1320
}
1421

1522
/**
1623
* Generate a URL for executing API calls
17-
* @param [type] $website [description]
24+
*
25+
* @param string $website
26+
* @param string $pageRoot
27+
* @param string $adminDir
28+
*
29+
* @return string
1830
*/
1931
public function apiUrl( $website, $pageRoot, $adminDir )
2032
{

plugins/restapi2/lib/Handler/ListHandler.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace Rapi\Handler;
44

5+
use phpList\Entity\ListEntity;
6+
use phpList\Entity\SubscriberEntity;
7+
use phpList\ListManager;
8+
59
/**
610
* Class to handle API calls to ListManager{}
711
*/
@@ -13,16 +17,22 @@ class ListHandler
1317
* @param ListManager $listManager
1418
*/
1519
public function __construct(
16-
\phpList\Entity\ListEntity $listEntity
17-
, \phpList\ListManager $listManager
18-
, \phpList\Entity\SubscriberEntity $scrEntity
20+
ListEntity $listEntity,
21+
ListManager $listManager,
22+
SubscriberEntity $scrEntity
1923
)
2024
{
2125
$this->listEntity = $listEntity;
2226
$this->listManager = $listManager;
2327
$this->scrEntity = $scrEntity;
2428
}
2529

30+
/**
31+
* @param int $listId
32+
* @param int $scrId
33+
*
34+
* @return \PDOStatement|null
35+
*/
2636
public function addSubscriber( $listId, $scrId )
2737
{
2838
// Save the id to the subscriber entity

plugins/restapi2/lib/Handler/LoginHandler.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Rapi\Handler;
44
use phpList\helper\Logger;
5+
use Rapi\Admin;
56

67
/**
78
* Class LoginHandler
@@ -12,14 +13,21 @@ class LoginHandler
1213

1314
/**
1415
* LoginHandler constructor.
15-
* @param \Rapi\Admin $admin
16+
*
17+
* @param Admin $admin
18+
* @param Logger $logger
1619
*/
17-
public function __construct( \Rapi\Admin $admin, Logger $logger)
20+
public function __construct( Admin $admin, Logger $logger)
1821
{
1922
$this->admin = $admin;
2023
$logger->debug('LoginHandler was called');
2124
}
2225

26+
/**
27+
* @param string $username
28+
* @param string $password
29+
* @return array
30+
*/
2331
public function login($username, $password){
2432
$data = $this->admin->login($username, $password);
2533
if($data){

0 commit comments

Comments
 (0)