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

Feature/1159 add phpstan #1165

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ parameters:
excludePaths:
analyse:
- */vendor/*
- %currentWorkingDirectory%/go/core/util/QRcode.php

reportUnmatchedIgnoredErrors: false
treatPhpDocTypesAsCertain: false
ignoreErrors:
- identifier: staticMethod.private
- identifier: staticProperty.private
- identifier: missingType.iterableValue
- identifier: missingType.generics
- '#Class .* referenced with incorrect case: .*#'
- '#Variable .* in empty\(\) always exists and is always falsy.#'
- '#Variable .* in empty\(\) always exists and is not falsy.#'
- '#Variable .* in isset\(\) always exists and is always null.#'
- '#Unsafe usage of new static\(\).#'
- '#Unsafe access to private property .*#'
- '#Unsafe call to private method .*#'
6 changes: 5 additions & 1 deletion www/go/base/db/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @property String $localizedName The localized human friendly name of this model.
* @property int $permissionLevel @see \GO\Base\Model\Acl for available levels. Returns -1 if no aclField() is set in the model.
*
* @property GO\Files\Model\Folder $filesFolder The folder model that belongs to this model if hasFiles is true.
* @property \GO\Files\Model\Folder $filesFolder The folder model that belongs to this model if hasFiles is true.
*/


Expand All @@ -59,6 +59,10 @@
use go\core\util\StringUtil;
use go\modules\community\comments\model\Comment;

/**
* @property int $ctime
* @property int $mtime
*/
abstract class ActiveRecord extends \GO\Base\Model{
const EVENT_URL = "url";

Expand Down
4 changes: 2 additions & 2 deletions www/go/base/util/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public function setCurlOption($option, $value){
* Make a POST request to any URL
*
* @param string $url
* @param string $params POST parameters
* @param array $params POST parameters
* @return string Response of the server.
* @throws Exception
* @throws \Exception
*/
public function request($url, $params=array()){

Expand Down
4 changes: 3 additions & 1 deletion www/go/core/ldap/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* @license AGPL/Proprietary http://www.group-office.com/LICENSE.TXT
* @link http://www.group-office.com
* @copyright Copyright Intermesh BV
* @author Merijn Schering <[email protected]>
* @author Merijn Schering <[email protected]>
*
* @property string $cn
*/
class Record {

Expand Down
2 changes: 1 addition & 1 deletion www/go/core/model/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Token extends Entity {

/**
* Time this token expires. Defaults to one day after the token was created {@see LIFETIME}
* @var DateTime
* @var ?DateTime
*/
public $expiresAt;

Expand Down
2 changes: 1 addition & 1 deletion www/go/core/util/BackgroundProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function isRunning(int $pid) : bool{
if( count(preg_split("/\n/", $result)) > 2){
return true;
}
}catch(Exception $e){}
}catch(\Exception $e){}

return false;
}
Expand Down
5 changes: 3 additions & 2 deletions www/go/core/util/ClassFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static function getDefaultNamespaces(): array

if($ns === null) {
$ns = ['go\\core'];


/** @var Module[] $modules */
$modules = Module::find()->where(['enabled' => true]);
foreach ($modules as $module) {
if(!isset($module->package) || $module->package == "core" || !$module->isAvailable()) {
Expand Down Expand Up @@ -79,7 +80,7 @@ public function addNamespace(string $namespace, Folder $folder = null) {
/**
* Find all classes
*
* @param string[] Full class name without leading "\" eg. ["IFW\App"]
* @return string[] Full class name without leading "\" eg. ["IFW\App"]
*/
public function find(): array
{
Expand Down
15 changes: 7 additions & 8 deletions www/go/core/util/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ public static function encrypt(string $plaintext, string $password = null): stri

/** Decryption Procedure
*
* @param string msg output from encrypt()
* @param string k encryption key
* @param boolean base64 base64 decode msg
* @param string $ciphertext output from encrypt()
* @param string $password encryption key
*
* @return string original message/data or
* boolean false on error
Expand Down Expand Up @@ -153,11 +152,11 @@ private static function decrypt1(string $msg, ?string $k = null, bool $base64 =

/** PBKDF2 Implementation (as described in RFC 2898);
*
* @param string p password
* @param string s salt
* @param int c iteration count (use 1000 or higher)
* @param int kl derived key length
* @param string a hash algorithm
* @param string $p password
* @param string $s salt
* @param int $c iteration count (use 1000 or higher)
* @param int $kl derived key length
* @param string $a hash algorithm
*
* @return string derived key
*/
Expand Down
2 changes: 1 addition & 1 deletion www/go/core/util/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function fixOrientation() {
/**
* Output image to browser
*
* @param int $image_type
* @param int|false $image_type
* @throws Exception
*/
public function output($image_type = false) {
Expand Down
2 changes: 1 addition & 1 deletion www/go/core/util/IniFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function __toString() {
*
* @param mixed $value
*
* @return string
* @return string|float|int
*/
private static function encode($value) {

Expand Down
4 changes: 2 additions & 2 deletions www/go/core/util/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Lock {
private static $locks = [];

/**
* @var resource
* @var null|\SysvSemaphore|false
*/
private $sem;
/**
Expand Down Expand Up @@ -58,7 +58,7 @@ public static function exists(string $name) : bool {
/**
* The file pinter for the lock method
*
* @var resource
* @var ?resource
*/
private $lockFp;

Expand Down
2 changes: 1 addition & 1 deletion www/go/core/util/PdfTemplateRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function Footer() {
*
* $pdf->render()->Output($file->getPath(), "F");
*
* @return PdfTemplateRenderer
* @return PdfRenderer
* @throws Exception
*/
public function render() {
Expand Down
1 change: 0 additions & 1 deletion www/go/core/util/Recurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Recurrence extends RRuleIterator {

/**
* Recurrence constructor.
* @param string $rrule RRULE FORMAT AS IN
* @param DateTimeInterface $start
* @throws InvalidDataException
* @noinspection PhpMissingParentConstructorInspection
Expand Down
12 changes: 4 additions & 8 deletions www/go/core/util/StringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function normalize(string $text): string
/**
* Check if UTF-8 string is in FORM_C
*
* @param $text
* @param string $text
* @return bool
*/
public static function isNormalized($text): bool
Expand All @@ -81,7 +81,6 @@ public static function isNormalized($text): bool
/**
* Converts any "CamelCased" into an "underscored_word".
* @param string $camelCasedString the word(s) to underscore
* @param string
* @return string
*/
public static function camelCaseToUnderscore(string $camelCasedString): string
Expand All @@ -94,7 +93,6 @@ public static function camelCaseToUnderscore(string $camelCasedString): string
*
* @param ?string $str
* @param string|null $sourceCharset
* @param string
* @return string
*/
public static function cleanUtf8(?string $str, string $sourceCharset = null): string
Expand Down Expand Up @@ -498,7 +496,6 @@ public static function isUtf8(string $str): bool
* @param string $replace
* @param string $subject
* @param bool $found Pass this to check if an occurence was replaced or not
* @param string
* @return string
*/
public static function replaceOnce(string $search, string $replace, string $subject, bool &$found = false): string
Expand Down Expand Up @@ -557,7 +554,7 @@ public static function cutString(?string $str, int $maxLength, bool $cutWholeWor
* Convert plain text to HTML
*
* @param string $text Plain text string
* @param string HTML formatted string
* @param bool $convertLinks Whether to convert URLs to links
* @return string
*/
public static function textToHtml(string $text, $convertLinks = true): string
Expand Down Expand Up @@ -685,7 +682,6 @@ public static function length(string $str): int
* eg. message_id or message-id will become messageId
*
* @param string $str
* @param string
* @return string
*/
public static function lowerCamelCasify(string $str): string
Expand Down Expand Up @@ -774,7 +770,7 @@ public static function random(int $length): string

/**
* Converts to ASCII.
* @param string UTF-8 encoding
* @param string $str UTF-8 encoding
* @return string ASCII
*
* @see https://3v4l.org/CiH8j
Expand Down Expand Up @@ -894,7 +890,7 @@ public static function splitTextKeywords(?string $text, bool $forSave = true): a
* will already cover that.
*
* @param array $keywords
* @return void
* @return array
*/
public static function filterRedundantSearchWords(array $keywords) : array {
$keywords = array_unique($keywords);
Expand Down
2 changes: 1 addition & 1 deletion www/go/core/validate/ValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getValidationErrorsAsString(): string
* If the attribute has no error then fals will be returned
*
* @param string $key
* @return array{code:int, description:string, data:array}|false eg. array('code'=>'maxLength','info'=>array('length'=>10))
* @return array{code:string, description:string, data:array}|false eg. array('code'=>'maxLength','info'=>array('length'=>10))
*/
public function getValidationError($key) {
$validationErrors = $this->getValidationErrors();
Expand Down
2 changes: 1 addition & 1 deletion www/go/modules/community/addressbook/model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Address extends Property {

/**
* ISO 3601 2 char country code. eg. "NL".
* @var string
* @var ?string
*/
public $countryCode;

Expand Down
12 changes: 6 additions & 6 deletions www/go/modules/community/addressbook/model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,36 @@ class Contact extends AclItemEntity {

/**
* Prefixes like 'Sir'
* @var string
* @var ?string
*/
public $prefixes = '';

/**
* @var string
* @var ?string
*/
public $initials = '';

/**
*
* @var string
* @var ?string
*/
public $firstName = '';

/**
*
* @var string
* @var ?string
*/
public $middleName = '';

/**
*
* @var string
* @var ?string
*/
public $lastName = '';

/**
* Suffixes like 'Msc.'
* @var string
* @var ?string
*/
public $suffixes = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
die("Failed to send request!" . curl_error($ch));
}

$responses = json_decode($result, true);
$responses = json_decode($result, true, 512, JSON_THROW_ON_ERROR);

$success = $responses[0][1]['updated'][1]['settings']['maintenanceMode'] ?? false;

Expand Down
5 changes: 3 additions & 2 deletions www/go/modules/community/carddav/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public function createCard($addressBookId, $cardUri, $cardData): string
throw new Forbidden();
}
}

$vcardComp = Reader::read($cardData, Reader::OPTION_FORGIVING + Reader::OPTION_IGNORE_INVALID_LINES);
/** @var $vcardComp VCardComp */
/** @var VCardComp $vcardComp */
$contact = new Contact();
$contact->addressBookId = (int) $addressBookId;
$contact->setUid((string) $vcardComp->uid);
Expand Down Expand Up @@ -132,6 +132,7 @@ private function createBlob(Contact $contact, $cardData): Blob
*/
public function deleteCard($addressBookId, $cardUri): bool {

/** @phpstan-ignore-next-line */
if(!go()->getAuthState()->getUser(['syncSettings'])->syncSettings->allowDeletes) {
go()->debug("Deleting is disabled by user sync settings");
throw new Forbidden("Deleting is disabled by user sync settings");
Expand Down
4 changes: 2 additions & 2 deletions www/go/modules/community/comments/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static function demoText(Faker\Generator $faker) : string{
if(!isset(static::$demoTexts )) {
static::$demoTexts = [];
for($i = 0; $i < 20; $i++) {
static::$demoTexts [] = nl2br($faker->realtext);
static::$demoTexts [] = nl2br($faker->realText);
}
}

Expand All @@ -102,7 +102,7 @@ private static function demoText(Faker\Generator $faker) : string{
private static $demoUsers;

/**
* @return User[]
* @return \go\core\model\User[]
*/
private static function demoUsers(): array
{
Expand Down
2 changes: 1 addition & 1 deletion www/go/modules/community/comments/model/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function findAclEntity()
*
* @param ActiveRecord|Entity $entity
* @param array $properties
* @return Query<Comment>
* @return Query<$this>
* @throws Exception
*/
public static function findFor(ActiveRecord|Entity $entity, array $properties = []) : Query {
Expand Down
2 changes: 1 addition & 1 deletion www/go/modules/community/dev/cli/controller/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Language extends Controller {
* docker-compose exec groupoffice-64 php www/cli.php community/dev/Language/import --path=lang.csv
* ```
*
* @param type $params
* @param array $params
* @throws \Exception
*/
public function import($params) {
Expand Down
10 changes: 6 additions & 4 deletions www/go/modules/community/dev/controller/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use go\core\cache\None;
use go\core\Controller;
use go\core\Environment;
use go\core\exception\Unauthorized;
use go\core\fs\Blob;
use go\core\fs\File;
use go\core\jmap\Response;
Expand All @@ -20,10 +21,11 @@ class Language extends Controller {
const DELIMITER = ';';
const ENCLOSURE = '"';

protected function authenticate() {
if (!go()->getAuthState()->isAuthenticated()) {
throw new Exception(401, "Unauthorized");
}
protected function authenticate()
{
if (!go()->getAuthState()->isAuthenticated()) {
throw new Unauthorized();
}
}

public function export($params) {
Expand Down
Loading