Fix more phpstan code issues

This commit is contained in:
Aleksander Machniak 2024-04-16 08:58:06 +02:00
parent 31ab2dfe9c
commit cbc8078c79
11 changed files with 91 additions and 28 deletions

View file

@ -9,16 +9,9 @@ parameters:
ignoreErrors:
# TODO: These need to be fixed somehow
- '#Access to an undefined property (calendar|tasklist)::\$driver#'
- '#Access to an undefined property (calendar|tasklist)::\$itip#'
- '#Access to an undefined property (calendar|tasklist)::\$ical#'
- '#Access to an undefined property Kolab2FA\\.*::\$(username|secret)#'
- '#Access to an undefined property Sabre\\VObject.*::\$.*#'
- '#Access to an undefined property DateTime::\$_dateonly#'
# All expressions below are about libkolabxml (which I don't have installed)
- '#unknown class (kolabformat|Address|Alarm|Contact|ContactReference|Configuration|Email|RecurrenceRule|Key|Related|Url|Snippet|Telephone)#'
- '#class (Address|Affiliation|Alarm|Attachment|Attendee|Duration|ContactReference|Configuration|Dictionary|Email|EmailReference|DayPos|FileDriver|Key|NameComponents|SnippetCollection|RecurrenceRule|Related|Relation|EventCal|Snippet|Telephone|Url|vector.*|cDatetime|XMLObject|CustomProperty) not found#i'
- '#Call to method .* on an unknown class (Affiliation|Attachment|Attendee|cDateTime|Dictionary|EventCal|FileDriver|NameComponents|Relation|snippet|vector.*)#'
- '#class (Address|Affiliation|Alarm|Attachment|Attendee|Duration|Contact|ContactReference|Configuration|Dictionary|Email|EmailReference|EventCal|DayPos|FileDriver|Key|NameComponents|SnippetCollection|RecurrenceRule|Related|Relation|EventCal|Snippet|Telephone|Url|vector.*|kolabformat|cDatetime|XMLObject|CustomProperty)#i'
- '#invalid .*type vector#'
- '#(cDateTime|EventCal)#'
@ -32,3 +25,8 @@ parameters:
- program/actions
treatPhpDocTypesAsCertain: false
universalObjectCratesClasses:
- Sabre\VObject\Component
- Sabre\VObject\Component\VEvent
- Sabre\VObject\Component\VTodo

View file

@ -23,6 +23,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Calendar plugin
*
* @property calendar_driver $driver
* @property libcalendaring_vcalendar $ical
* @property libcalendaring_itip $itip
*/
#[AllowDynamicProperties]
class calendar extends rcube_plugin
{
@ -69,11 +76,6 @@ class calendar extends rcube_plugin
private $token;
// These are implemented with __get()
// private $ical;
// private $itip;
// private $driver;
/**
* Plugin initialization.
@ -3130,7 +3132,7 @@ $("#rcmfd_new_category").keypress(function(event) {
} elseif ($existing
&& ($this->event['sequence'] >= $existing['sequence']
|| $this->event['changed'] >= $existing['changed'])
&& ($calendar = $this->driver->get_calendar($existing['calendar']))
&& ($calendar = $this->driver->get_calendar_name($existing['calendar']))
) {
$this->event = $invitation['event'];
$this->event['id'] = $existing['id'];
@ -3150,7 +3152,7 @@ $("#rcmfd_new_category").keypress(function(event) {
}
if ($this->driver->edit_event($this->event)) {
$msg = $this->gettext(['name' => 'updatedsuccessfully', 'vars' => ['calendar' => $calendar->get_name()]]);
$msg = $this->gettext(['name' => 'updatedsuccessfully', 'vars' => ['calendar' => $calendar]]);
$this->rc->output->command('display_message', $msg, 'confirmation');
} else {
$this->rc->output->command('display_message', $this->gettext('errorimportingevent'), 'error');

View file

@ -294,7 +294,7 @@ class caldav_driver extends kolab_driver
*
* @param string $id Calendar identifier
*
* @return caldav_calendar|caldav_invitation_calendar|null Object nor null if calendar doesn't exist
* @return caldav_calendar|caldav_invitation_calendar|null Object or null if calendar doesn't exist
*/
public function get_calendar($id)
{
@ -318,6 +318,20 @@ class caldav_driver extends kolab_driver
return !empty($this->calendars[$id]) ? $this->calendars[$id] : null;
}
/**
* Get a calendar name for the given calendar ID
*
* @param string $id Calendar identifier
*
* @return string|null Calendar name if found
*/
public function get_calendar_name($id)
{
$cal = $this->get_calendar($id);
return $cal ? $cal->get_name() : null;
}
/**
* Create a new calendar assigned to the current user
*

View file

@ -128,10 +128,11 @@ abstract class calendar_driver
*
* @param int $filter Bitmask defining filter criterias.
* See FILTER_* constants for possible values.
* @param ?kolab_storage_folder_virtual $tree Reference to hierarchical folder tree object
*
* @return array List of calendars
*/
abstract public function list_calendars($filter = 0);
abstract public function list_calendars($filter = 0, &$tree = null);
/**
* Create a new calendar assigned to the current user
@ -158,6 +159,15 @@ abstract class calendar_driver
*/
abstract public function edit_calendar($prop);
/**
* Get a calendar name for the given calendar ID
*
* @param string $id Calendar identifier
*
* @return string|null Calendar name if found
*/
abstract public function get_calendar_name($id);
/**
* Set active/subscribed state of a calendar
*

View file

@ -105,11 +105,12 @@ class database_driver extends calendar_driver
/**
* Get a list of available calendars from this source
*
* @param int $filter Bitmask defining filter criterias
* @param int $filter Bitmask defining filter criterias
* @param ?kolab_storage_folder_virtual $tree Reference to hierarchical folder tree object
*
* @return array List of calendars
*/
public function list_calendars($filter = 0)
public function list_calendars($filter = 0, &$tree = null)
{
// attempt to create a default calendar for this user
if (empty($this->calendars)) {
@ -156,6 +157,18 @@ class database_driver extends calendar_driver
return $calendars;
}
/**
* Get a calendar name for the given calendar ID
*
* @param string $id Calendar identifier
*
* @return string|null Calendar name if found
*/
public function get_calendar_name($id)
{
return $this->calendars[$id]['name'] ?? null;
}
/**
* Create a new calendar assigned to the current user
*

View file

@ -352,7 +352,7 @@ class kolab_driver extends calendar_driver
*
* @param string $id Calendar identifier (encoded imap folder name)
*
* @return kolab_calendar|kolab_invitation_calendar|null Object nor null if calendar doesn't exist
* @return kolab_calendar|kolab_invitation_calendar|null Object or null if calendar doesn't exist
*/
public function get_calendar($id)
{
@ -376,6 +376,20 @@ class kolab_driver extends calendar_driver
return !empty($this->calendars[$id]) ? $this->calendars[$id] : null;
}
/**
* Get a calendar name for the given calendar ID
*
* @param string $id Calendar identifier
*
* @return string|null Calendar name if found
*/
public function get_calendar_name($id)
{
$cal = $this->get_calendar($id);
return $cal ? $cal->get_name() : null;
}
/**
* Create a new calendar assigned to the current user
*

View file

@ -227,7 +227,6 @@ class calendar_ui
$calendars = $this->cal->driver->list_calendars(0, $tree);
// walk folder tree
// @phpstan-ignore-next-line
if (is_object($tree)) {
$html = $this->list_tree_html($tree, $calendars, $jsenv, $attrib);

View file

@ -23,6 +23,12 @@
namespace Kolab2FA\Driver;
/**
* Kolab 2-Factor-Authentication Driver base class
*
* @property string $username
* @property string $secret
*/
abstract class Base
{
public $method;

View file

@ -1018,12 +1018,12 @@ class libcalendaring_vcalendar implements Iterator
// encapsulate in VCALENDAR container
$vcal = new VObject\Component\VCalendar();
$vcal->VERSION = '2.0'; // @phpstan-ignore-line
$vcal->PRODID = $this->prodid; // @phpstan-ignore-line
$vcal->CALSCALE = 'GREGORIAN'; // @phpstan-ignore-line
$vcal->VERSION = '2.0';
$vcal->PRODID = $this->prodid;
$vcal->CALSCALE = 'GREGORIAN';
if (!empty($method)) {
$vcal->METHOD = $method; // @phpstan-ignore-line
$vcal->METHOD = $method;
}
// write vcalendar header

View file

@ -548,8 +548,8 @@ class VcalendarTest extends PHPUnit\Framework\TestCase
{
$vtz = libcalendaring_vcalendar::get_vtimezone('Europe/Berlin', strtotime('2014-08-22T15:00:00+02:00'));
$this->assertInstanceOf('\Sabre\VObject\Component', $vtz, "VTIMEZONE is a Component object");
$this->assertEquals('Europe/Berlin', $vtz->TZID); // @phpstan-ignore-line
$this->assertEquals('4', $vtz->{'X-MICROSOFT-CDO-TZID'}); // @phpstan-ignore-line
$this->assertEquals('Europe/Berlin', $vtz->TZID);
$this->assertEquals('4', $vtz->{'X-MICROSOFT-CDO-TZID'});
// check for transition to daylight saving time which is BEFORE the given date
$dst = array_first($vtz->select('DAYLIGHT'));

View file

@ -22,6 +22,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Tasklist plugin
*
* @property tasklist_driver $driver
* @property libcalendaring_vcalendar $ical
* @property libcalendaring_itip $itip
*/
#[AllowDynamicProperties]
class tasklist extends rcube_plugin
{
@ -2282,7 +2289,7 @@ class tasklist extends rcube_plugin
$existing['free_busy'] = 'free';
}
$success = $this->driver->edit_event($existing);
$success = $this->driver->edit_task($existing);
} else {
$error_msg = $this->gettext('newerversionexists');
}