refactor: use phpstan for code analysis

pull/63/head
sualko 2020-06-19 10:49:40 +02:00
parent 7242360bd8
commit 6234a591d6
11 changed files with 123 additions and 24 deletions

View File

@ -15,7 +15,8 @@
"require-dev": { "require-dev": {
"phpunit/phpunit": "^8", "phpunit/phpunit": "^8",
"friendsofphp/php-cs-fixer": "^2.16", "friendsofphp/php-cs-fixer": "^2.16",
"nextcloud/coding-standard": "^0.3.0" "nextcloud/coding-standard": "^0.3.0",
"phpstan/phpstan": "^0.12.29"
}, },
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,

58
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "a5f7d2fab7db00ef99eb9468c2fa9a0a", "content-hash": "6889c8d8926c05b33570a53abc170e3f",
"packages": [ "packages": [
{ {
"name": "littleredbutton/bigbluebutton-api-php", "name": "littleredbutton/bigbluebutton-api-php",
@ -1026,6 +1026,62 @@
], ],
"time": "2020-03-05T15:02:03+00:00" "time": "2020-03-05T15:02:03+00:00"
}, },
{
"name": "phpstan/phpstan",
"version": "0.12.29",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "9771daaf6b95c6313b908d0bcdee0afcd51f838a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/9771daaf6b95c6313b908d0bcdee0afcd51f838a",
"reference": "9771daaf6b95c6313b908d0bcdee0afcd51f838a",
"shasum": ""
},
"require": {
"php": "^7.1"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.12-dev"
}
},
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://www.patreon.com/phpstan",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2020-06-14T14:10:59+00:00"
},
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "7.0.10", "version": "7.0.10",

View File

@ -24,7 +24,7 @@ class API {
/** @var Permission */ /** @var Permission */
private $permission; private $permission;
/** @var BigBlueButton */ /** @var BigBlueButton|null */
private $server; private $server;
public function __construct( public function __construct(

View File

@ -10,7 +10,6 @@ use OCA\BigBlueButton\NotFoundException;
use OCA\BigBlueButton\Permission; use OCA\BigBlueButton\Permission;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
use OCP\IRequest; use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\IConfig; use OCP\IConfig;
@ -22,7 +21,7 @@ class JoinController extends Controller {
/** @var string */ /** @var string */
protected $token; protected $token;
/** @var Room */ /** @var Room|null */
protected $room; protected $room;
/** @var RoomService */ /** @var RoomService */
@ -46,7 +45,6 @@ class JoinController extends Controller {
public function __construct( public function __construct(
string $appName, string $appName,
IRequest $request, IRequest $request,
ISession $session,
RoomService $service, RoomService $service,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
IUserSession $userSession, IUserSession $userSession,
@ -54,7 +52,7 @@ class JoinController extends Controller {
API $api, API $api,
Permission $permission Permission $permission
) { ) {
parent::__construct($appName, $request, $session); parent::__construct($appName, $request);
$this->service = $service; $this->service = $service;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;

View File

@ -80,7 +80,7 @@ class ServerController extends Controller {
return new DataResponse($success); return new DataResponse($success);
} }
public function check(string $url, string $secret) { public function check(?string $url, ?string $secret) {
if ($url === null || empty($url) || $secret === null || empty($secret)) { if ($url === null || empty($url) || $secret === null || empty($secret)) {
return new DataResponse(false); return new DataResponse(false);
} }
@ -88,7 +88,7 @@ class ServerController extends Controller {
return new DataResponse($this->server->check($url, $secret)); return new DataResponse($this->server->check($url, $secret));
} }
public function version(string $url) { public function version(?string $url) {
if ($url === null || empty($url)) { if ($url === null || empty($url)) {
return new DataResponse(false, Http::STATUS_NOT_FOUND); return new DataResponse(false, Http::STATUS_NOT_FOUND);
} }

View File

@ -6,6 +6,30 @@ use JsonSerializable;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
/**
* @method string getUid()
* @method string getName()
* @method string getAttendeePassword()
* @method string getModeratorPassword()
* @method string getWelcome()
* @method int getMaxParticipants()
* @method bool getRecord()
* @method string getUserId()
* @method string getAccess()
* @method string getPassword()
* @method bool getEveryoneIsModerator()
* @method void setUid(string $uid)
* @method void setName(string $name)
* @method void setAttendeePassword(string $pw)
* @method void setModeratorPassword(string $pw)
* @method void setWelcome(string $welcome)
* @method void setMaxParticipants(int $max)
* @method void setRecord(bool $record)
* @method void setUserId(string $userId)
* @method void setAccess(string $access)
* @method void setPassword(string $pw)
* @method void setEveryoneIsModerator(bool $everyone)
*/
class Room extends Entity implements JsonSerializable { class Room extends Entity implements JsonSerializable {
public const ACCESS_PUBLIC = 'public'; public const ACCESS_PUBLIC = 'public';
public const ACCESS_PASSWORD = 'password'; public const ACCESS_PASSWORD = 'password';

View File

@ -3,7 +3,6 @@
namespace OCA\BigBlueButton\Db; namespace OCA\BigBlueButton\Db;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper; use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
@ -14,9 +13,6 @@ class RoomMapper extends QBMapper {
} }
/** /**
* @param int $id
* @param string $userId
* @return Entity|Room
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException * @throws DoesNotExistException
*/ */
@ -26,12 +22,12 @@ class RoomMapper extends QBMapper {
$qb->select('*') $qb->select('*')
->from($this->tableName) ->from($this->tableName)
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
/** @var Room */
return $this->findEntity($qb); return $this->findEntity($qb);
} }
/** /**
* @param string $uid
* @return Entity|Room
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException * @throws DoesNotExistException
*/ */
@ -41,13 +37,13 @@ class RoomMapper extends QBMapper {
$qb->select('*') $qb->select('*')
->from($this->tableName) ->from($this->tableName)
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
/** @var Room */
return $this->findEntity($qb); return $this->findEntity($qb);
} }
/** /**
* @param int $userId * @return array<Room>
* @param array $groupIds
* @return array
*/ */
public function findAll(string $userId, array $groupIds): array { public function findAll(string $userId, array $groupIds): array {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
@ -71,6 +67,8 @@ class RoomMapper extends QBMapper {
) )
) )
->groupBy('r.id'); ->groupBy('r.id');
/** @var array<Room> */
return $this->findEntities($qb); return $this->findEntities($qb);
} }
} }

View File

@ -6,6 +6,19 @@ use JsonSerializable;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
/**
* @method int getRoomId()
* @method int getShareType()
* @method string getShareWith()
* @method string|null getShareWithDisplayName()
* @method int getPermission()
* @method void setShareWithDisplayName(string $displayName)
* @method void setRoomId(int $id)
* @method void setShareType(int $type)
* @method void setShareWith(string $with)
* @method void setShareWithDisplayName(string $displayName)
* @method void setPermission(int $permission)
*/
class RoomShare extends Entity implements JsonSerializable { class RoomShare extends Entity implements JsonSerializable {
public const PERMISSION_ADMIN = 0; public const PERMISSION_ADMIN = 0;
public const PERMISSION_MODERATOR = 1; public const PERMISSION_MODERATOR = 1;

View File

@ -3,7 +3,6 @@
namespace OCA\BigBlueButton\Db; namespace OCA\BigBlueButton\Db;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper; use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
@ -14,8 +13,6 @@ class RoomShareMapper extends QBMapper {
} }
/** /**
* @param int $id
* @return Entity|RoomShare
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException * @throws DoesNotExistException
*/ */
@ -25,9 +22,15 @@ class RoomShareMapper extends QBMapper {
$qb->select('*') $qb->select('*')
->from('bbb_room_shares') ->from('bbb_room_shares')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
/** @var RoomShare */
return $this->findEntity($qb); return $this->findEntity($qb);
} }
/**
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
public function findByRoomAndEntity(int $roomId, string $shareWith, int $shareType): RoomShare { public function findByRoomAndEntity(int $roomId, string $shareWith, int $shareType): RoomShare {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
@ -37,15 +40,21 @@ class RoomShareMapper extends QBMapper {
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($shareWith))) ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($shareWith)))
->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType, IQueryBuilder::PARAM_INT))); ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType, IQueryBuilder::PARAM_INT)));
/** @var RoomShare */
return $this->findEntity($qb); return $this->findEntity($qb);
} }
/**
* @return array<RoomShare>
*/
public function findAll(int $roomId): array { public function findAll(int $roomId): array {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
->from('bbb_room_shares') ->from('bbb_room_shares')
->where($qb->expr()->eq('room_id', $qb->createNamedParameter($roomId, IQueryBuilder::PARAM_INT))); ->where($qb->expr()->eq('room_id', $qb->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
/** @var array<RoomShare> */
return $this->findEntities($qb); return $this->findEntities($qb);
} }
} }

View File

@ -32,6 +32,9 @@ class RoomService {
} }
} }
/**
* @throws RoomNotFound
*/
public function find($id): Room { public function find($id): Room {
try { try {
return $this->mapper->find($id); return $this->mapper->find($id);

View File

@ -5,7 +5,6 @@ namespace OCA\BigBlueButton\Tests\Controller;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\ISession;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\IConfig; use OCP\IConfig;
use OCP\IRequest; use OCP\IRequest;
@ -34,7 +33,6 @@ class JoinControllerTest extends TestCase {
parent::setUp(); parent::setUp();
$this->request = $this->createMock(IRequest::class); $this->request = $this->createMock(IRequest::class);
$this->session = $this->createMock(ISession::class);
$this->service = $this->createMock(RoomService::class); $this->service = $this->createMock(RoomService::class);
$this->userSession = $this->createMock(IUserSession::class); $this->userSession = $this->createMock(IUserSession::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
@ -45,7 +43,6 @@ class JoinControllerTest extends TestCase {
$this->controller = new JoinController( $this->controller = new JoinController(
'bbb', 'bbb',
$this->request, $this->request,
$this->session,
$this->service, $this->service,
$this->urlGenerator, $this->urlGenerator,
$this->userSession, $this->userSession,