Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/static analysis #263

Merged
merged 13 commits into from
Sep 17, 2024
2 changes: 0 additions & 2 deletions app/module/admin/manager/AdminManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Description of AdminManager
*
* @author kminekmatej, 25. 10. 2021
*/
class AdminManager
{
Expand Down
16 changes: 6 additions & 10 deletions app/module/admin/manager/MigrationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

/**
* Description of MigrationManager
*
* @author Matěj Kmínek
*/
class MigrationManager
{
Expand Down Expand Up @@ -126,8 +124,9 @@ private function saveMigrationsCache(): void
/**
* Drop all comments from file and get just array of sql queries
*
* @throws Exception When there are no commands
* @return string[]
*
* @throws Exception When there are no commands
*/
public function getCommands(string $contents): array
{
Expand Down Expand Up @@ -168,9 +167,7 @@ private function removeRemarks(string $sql): string
$lines = explode("\n", $sql);

$output = [];
$i = 0;
foreach ($lines as $line) {
$i++;
$lineT = trim($line);
$lineT = str_replace(' ', ' ', $lineT);
if ($lineT === '') {
Expand All @@ -192,6 +189,7 @@ private function removeRemarks(string $sql): string
/**
* Split an uploaded sql file into single sql statements.
* Note: expects trim() to have already been run on $sql.
*
* @return string[]
*/
private function splitSqlFile(string $sql, string $delimiter): array
Expand All @@ -207,14 +205,13 @@ private function splitSqlFile(string $sql, string $delimiter): array
}

// try to save mem.
$sql = "";
$output = [];

// we don't actually care about the matches preg gives us.
$matches = [];

// this is faster than calling count($oktens) every time thru the loop.
$token_count = is_countable($tokens) ? count($tokens) : 0;
$token_count = count($tokens);
for ($i = 0; $i < $token_count; $i++) {
// Don't wanna add an empty string as the last thing in the array.
if (($i !== $token_count - 1) || (strlen($tokens[$i] > 0))) {
Expand Down Expand Up @@ -330,6 +327,7 @@ private function getAllMigrations(?string $latestMigration): array

/**
* Migrate database to latest version
*
* @return array<string, mixed[]>
*/
public function migrateUp(): array
Expand Down Expand Up @@ -375,11 +373,9 @@ private function migrateFromVersion1(): void
return; //no tables exists - this is a new system, simply perform the base migration to fill it
}

$migrationTableExists = in_array("migration", $tables);
if ($migrationTableExists) {
if (in_array("migration", $tables)) {
if ($this->teamDatabase->table("migration")->where("result", "OK")->count("id") == 0) { //migration table exists, but not containing any migration, so its some bloat, remove the table and continue
$this->teamDatabase->query("DROP TABLE IF EXISTS `migration`;")->fetch();
$migrationTableExists = false;
} else {
return; //there is already migration table structure, no neeed to continue
}
Expand Down
2 changes: 0 additions & 2 deletions app/module/admin/model/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

/**
* Description of Migration
*
* @author Matěj Kmínek
*/
class Migration
{
Expand Down
11 changes: 5 additions & 6 deletions app/module/admin/presenter/api/AdminSecuredPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace Tymy\Module\Admin\Presenter\Api;

use Nette\DI\Attributes\Inject;
use Tymy\Module\Admin\Manager\AdminManager;
use Tymy\Module\Core\Presenter\Api\BasePresenter;

/**
* Description of AdminSecuredPresenter
*
* @author kminekmatej, 25. 10. 2021
*/
class AdminSecuredPresenter extends BasePresenter
{
#[\Nette\DI\Attributes\Inject]
#[Inject]
public AdminManager $adminManager;

protected function startup(): void
Expand Down Expand Up @@ -42,10 +41,10 @@ private function getTokenFromHeader(string $header): ?string
}

if ($this->user->isLoggedIn()) {
$this->user->logout(true); //
$this->user->logout(true);
}

return is_string($headerContent) ? $headerContent : null;
return $headerContent;
}

/**
Expand All @@ -64,7 +63,7 @@ private function getTokenFromUrl(string $param): ?string
}

if ($this->user->isLoggedIn()) {
$this->user->logout(true); //
$this->user->logout(true);
}

return is_string($paramContent) ? $paramContent : null;
Expand Down
2 changes: 0 additions & 2 deletions app/module/admin/presenter/api/MigratePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

/**
* Description of MigratePresenter
*
* @author kminekmatej, 25. 10. 2021
*/
class MigratePresenter extends AdminSecuredPresenter
{
Expand Down
10 changes: 8 additions & 2 deletions app/module/attendance/manager/AttendanceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getByEventUserId(int $eventId, int $userId): ?Attendance

/**
* Get array of attendanced related to events
*
* @return array<int|string, array<Attendance|null>>
*/
public function getByEvents(array $eventIds): array
Expand All @@ -63,6 +64,7 @@ public function getByEvents(array $eventIds): array

/**
* Maps one active row to object
*
* @param IRow|null $row
* @param bool $force True to skip cache
* @return Attendance|null
Expand Down Expand Up @@ -104,6 +106,7 @@ public function getScheme(): array

/**
* Check edit permission
*
* @param Attendance $entity
*/
public function canEdit($entity, int $userId): bool
Expand All @@ -113,6 +116,7 @@ public function canEdit($entity, int $userId): bool

/**
* Check read permission
*
* @param Attendance $entity
*/
public function canRead($entity, int $userId): bool
Expand All @@ -122,6 +126,7 @@ public function canRead($entity, int $userId): bool

/**
* Get user ids allowed to read given attendance
*
* @param Attendance $record
* @return int[]
*/
Expand Down Expand Up @@ -305,8 +310,8 @@ public function create(array $data, ?int $resourceId = null): Attendance

$existingAttendance = $this->getByEventUserId($data["eventId"], $data["userId"]);
if (!$existingAttendance instanceof Attendance) {
$created = $this->createByArray($data);
if ($created && isset($data["preStatusId"])) {
$this->createByArray($data);
if (isset($data["preStatusId"])) {
$this->createHistory($data["userId"], $data["eventId"], $data["preStatusId"], $data["preDescription"] ?? null);
}
} else {
Expand All @@ -330,6 +335,7 @@ public function create(array $data, ?int $resourceId = null): Attendance
* @param array $updates Array of updates
* @param string $idColumn Caption of primary key column
* @return int number of affected rows
*
* @throws Exception
*/
protected function updateRecord(string $table, int $id, array $updates, string $idColumn = "id"): int
Expand Down
6 changes: 3 additions & 3 deletions app/module/attendance/manager/HistoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function __construct(ManagerFactory $managerFactory, private UserManager
}

/**
*
* @param ActiveRow|null $row
* @return History|null
*/
Expand Down Expand Up @@ -82,8 +81,9 @@ public function canEdit($entity, $userId): bool
*/
public function canRead($entity, int $userId): bool
{
assert($entity instanceof Event);
return $entity->getViewRightName() ? $this->user->isAllowed((string) $this->user->getId(), "USR:{$entity->getViewRightName()}") : true;
assert($entity instanceof History);
$eventRow = $this->database->table(Event::TABLE)->where("id", $entity->getEventId())->fetch();
return $eventRow->view_rights ? $this->user->isAllowed((string) $userId, "USR:{$eventRow->view_rights}") : true;
}

protected function allowRead(?int $recordId = null): void
Expand Down
6 changes: 6 additions & 0 deletions app/module/attendance/manager/StatusManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function getStatusSetFolder(int $statusSetId): string

/**
* Get all status unique status codes
*
* @return mixed[]
*/
public function getAllStatusCodes(): array
Expand All @@ -115,6 +116,7 @@ public function getAllStatusCodes(): array

/**
* Get all pre and post statuses by corresponding event type id
*
* @return array In the form of ["pre" => [..array of Status objects..], "post" => [..array of Status objects..]]
*/
public function getByEventTypeId(int $eventTypeId): array
Expand All @@ -130,6 +132,7 @@ public function getByEventTypeId(int $eventTypeId): array

/**
* Map all rows to array of statuses where key is status code
*
* @param ActiveRow[] $rows
* @return Status[]
*/
Expand All @@ -144,6 +147,7 @@ public function mapAllWithCode(array $rows): array

/**
* Get all status unique status codes
*
* @return Status[] where key is code
*/
public function getByStatusCode(): array
Expand All @@ -157,6 +161,7 @@ public function getByStatusCode(): array

/**
* Get all statuses, which are used in any event_type for pre-status purposes
*
* @return Status[] where key is code
*/
public function getAllPreStatuses(): array
Expand All @@ -170,6 +175,7 @@ public function getAllPreStatuses(): array

/**
* Load status ids related to specific event types - first PRE then POST statuses
*
* @param int $eventTypeId
* @return int[]
*/
Expand Down
5 changes: 2 additions & 3 deletions app/module/attendance/manager/StatusSetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ public function create(array $data, ?int $resourceId = null): BaseModel

$created = parent::createByArray($data);

if ($created) {
$this->createStatusSetDir($created->id);
}
$this->createStatusSetDir($created->id);

return $this->map($created);
}
Expand All @@ -159,6 +157,7 @@ public function read(int $resourceId, ?int $subResourceId = null): BaseModel

/**
* Get array of StatusSet objects which user is allowed to read
*
* @return StatusSet[]
*/
public function getListUserAllowed(int $userId): array
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/mapper/AttendanceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Description of AttendanceMapper
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 21. 9. 2020
*/
class AttendanceMapper extends BaseMapper
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/mapper/HistoryMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Description of HistoryMapper
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 19. 9. 2020
*/
class HistoryMapper extends BaseMapper
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/mapper/StatusMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Description of StatusMapper
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 4. 11. 2020
*/
class StatusMapper extends BaseMapper
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/mapper/StatusSetMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Description of StatusSetMapper
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 4. 11. 2020
*/
class StatusSetMapper extends BaseMapper
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/model/Attendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* Description of Attendance
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 21. 9. 2020
*/
class Attendance extends BaseModel implements JsonSerializable
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/model/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

/**
* Description of History
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 9. 10. 2020
*/
class History extends BaseModel
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/model/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

/**
* Description of Status
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 4. 11. 2020
*/
class Status extends BaseModel
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/model/StatusSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Description of StatusSet
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 4. 11. 2020
*/
class StatusSet extends BaseModel
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/presenter/api/DefaultPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

/**
* Description of DefaultPresenter
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 13. 9. 2020
*/
class DefaultPresenter extends SecuredPresenter
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/presenter/api/StatusPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

/**
* Description of StatusPresenter
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 3. 11. 2020
*/
class StatusPresenter extends SecuredPresenter
{
Expand Down
2 changes: 0 additions & 2 deletions app/module/attendance/router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Description of Router
*
* @author Matej Kminek <matej.kminek@attendees.eu>, 03. 11. 2020
*/
class Router implements RouterInterface
{
Expand Down
Loading