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": {
"phpunit/phpunit": "^8",
"friendsofphp/php-cs-fixer": "^2.16",
"nextcloud/coding-standard": "^0.3.0"
"nextcloud/coding-standard": "^0.3.0",
"phpstan/phpstan": "^0.12.29"
},
"config": {
"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",
"This file is @generated automatically"
],
"content-hash": "a5f7d2fab7db00ef99eb9468c2fa9a0a",
"content-hash": "6889c8d8926c05b33570a53abc170e3f",
"packages": [
{
"name": "littleredbutton/bigbluebutton-api-php",
@ -1026,6 +1026,62 @@
],
"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",
"version": "7.0.10",

View File

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

View File

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

View File

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

View File

@ -6,6 +6,30 @@ use JsonSerializable;
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 {
public const ACCESS_PUBLIC = 'public';
public const ACCESS_PASSWORD = 'password';

View File

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

View File

@ -6,6 +6,19 @@ use JsonSerializable;
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 {
public const PERMISSION_ADMIN = 0;
public const PERMISSION_MODERATOR = 1;

View File

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

View File

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

View File

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