Declare missing properties and methods for PHPStan

This commit is contained in:
Tautvidas Sipavičius
2019-01-23 21:30:24 +02:00
parent 44bc27df90
commit 1af4666744
14 changed files with 88 additions and 27 deletions

View File

@ -5,6 +5,10 @@ use MailPoet\Form\Block\Date;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
/**
* @property string $type
* @property string|array $params
*/
class CustomField extends Model { class CustomField extends Model {
public static $_table = MP_CUSTOM_FIELDS_TABLE; public static $_table = MP_CUSTOM_FIELDS_TABLE;
const TYPE_DATE = 'date'; const TYPE_DATE = 'date';

View File

@ -3,6 +3,10 @@ namespace MailPoet\Models;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
/**
* @property string|array $settings
* @property string|array $body
*/
class Form extends Model { class Form extends Model {
public static $_table = MP_FORMS_TABLE; public static $_table = MP_FORMS_TABLE;

View File

@ -29,13 +29,14 @@ if(!defined('ABSPATH')) exit;
* @method $this rawQuery($query, $parameters = array()) * @method $this rawQuery($query, $parameters = array())
* @method static $this rawQuery($query, $parameters = array()) * @method static $this rawQuery($query, $parameters = array())
* @method $this tableAlias($alias) * @method $this tableAlias($alias)
* @method static $this tableAlias($alias)
* @method int countNullIdColumns() * @method int countNullIdColumns()
* @method $this select($column, $alias=null) * @method $this select($column, $alias=null)
* @method static $this select($column, $alias=null) * @method static $this select($column, $alias=null)
* @method $this selectExpr($expr, $alias=null) * @method $this selectExpr($expr, $alias=null)
* @method static $this selectExpr($expr, $alias=null) * @method static $this selectExpr($expr, $alias=null)
* @method \ORM selectMany($values,...) * @method \ORM selectMany(...$values)
* @method static \ORM selectMany($values,...) * @method static \ORM selectMany(...$values)
* @method \ORM selectManyExpr($values) * @method \ORM selectManyExpr($values)
* @method $this rawJoin($table, $constraint, $table_alias, $parameters = array()) * @method $this rawJoin($table, $constraint, $table_alias, $parameters = array())
* @method $this innerJoin($table, $constraint, $table_alias=null) * @method $this innerJoin($table, $constraint, $table_alias=null)
@ -92,8 +93,16 @@ if(!defined('ABSPATH')) exit;
* @method static $this clearCache($table_name = null, $connection_name = self::DEFAULT_CONNECTION) * @method static $this clearCache($table_name = null, $connection_name = self::DEFAULT_CONNECTION)
* @method bool setExpr($key, $value = null) * @method bool setExpr($key, $value = null)
* @method bool isDirty($key) * @method bool isDirty($key)
* @method $this table_alias($alias) * @method static ORMWrapper filter(...$args)
* @method static $this table_alias($alias) * @method \ORMWrapper hasMany($associated_class_name, $foreign_key_name=null, $foreign_key_name_in_current_models_table=null, $connection_name=null)
* @method \ORMWrapper hasManyThrough($associated_class_name, $join_class_name=null, $key_to_base_table=null, $key_to_associated_table=null, $key_in_base_table=null, $key_in_associated_table=null, $connection_name=null)
* @method \ORMWrapper hasOne($associated_class_name, $foreign_key_name=null, $foreign_key_name_in_current_models_table=null, $connection_name=null)
* @method \ORMWrapper|bool create($data=null)
* @method static \ORMWrapper|bool create($data=null)
* @method int count()
* @method static int count()
*
* @property string|null $created_at
*/ */
class Model extends \Sudzy\ValidModel { class Model extends \Sudzy\ValidModel {
const DUPLICATE_RECORD = 23000; const DUPLICATE_RECORD = 23000;

View File

@ -10,6 +10,22 @@ use function MailPoet\Util\array_column;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
/**
* @property int $id
* @property string $type
* @property object $queue
* @property string $hash
* @property string $status
* @property string|object $meta
* @property array $options
* @property int $children_count
* @property bool|array $statistics
* @property string $deleted_at
* @property int $children_count
* @property int $total_sent
* @property int $total_scheduled
* @property array $segments
*/
class Newsletter extends Model { class Newsletter extends Model {
public static $_table = MP_NEWSLETTERS_TABLE; public static $_table = MP_NEWSLETTERS_TABLE;
const TYPE_AUTOMATIC = 'automatic'; const TYPE_AUTOMATIC = 'automatic';
@ -601,7 +617,7 @@ class Newsletter extends Model {
} }
static function sentAfter($date) { static function sentAfter($date) {
return static::table_alias('newsletters') return static::tableAlias('newsletters')
->where('newsletters.type', self::TYPE_STANDARD) ->where('newsletters.type', self::TYPE_STANDARD)
->where('newsletters.status', self::STATUS_SENT) ->where('newsletters.status', self::STATUS_SENT)
->join( ->join(
@ -951,7 +967,7 @@ class Newsletter extends Model {
} }
static function getWelcomeNotificationsForSegments($segments) { static function getWelcomeNotificationsForSegments($segments) {
return NewsletterOption::table_alias('options') return NewsletterOption::tableAlias('options')
->select('options.newsletter_id') ->select('options.newsletter_id')
->select('options.value', 'segment_id') ->select('options.value', 'segment_id')
->join( ->join(
@ -972,7 +988,7 @@ class Newsletter extends Model {
} }
static function getArchives($segment_ids = array()) { static function getArchives($segment_ids = array()) {
$orm = self::table_alias('newsletters') $orm = self::tableAlias('newsletters')
->distinct()->select('newsletters.*') ->distinct()->select('newsletters.*')
->select('newsletter_rendered_subject') ->select('newsletter_rendered_subject')
->whereIn('newsletters.type', array( ->whereIn('newsletters.type', array(

View File

@ -6,6 +6,11 @@ use MailPoet\WP\Functions as WPFunctions;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
/**
* @property int $id
* @property string $processed_at
* @property int $priority
*/
class ScheduledTask extends Model { class ScheduledTask extends Model {
public static $_table = MP_SCHEDULED_TASKS_TABLE; public static $_table = MP_SCHEDULED_TASKS_TABLE;
const STATUS_COMPLETED = 'completed'; const STATUS_COMPLETED = 'completed';

View File

@ -3,6 +3,10 @@ namespace MailPoet\Models;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
/**
* @property int $id
* @property array $subscribers_count
*/
class Segment extends Model { class Segment extends Model {
static $_table = MP_SEGMENTS_TABLE; static $_table = MP_SEGMENTS_TABLE;
const TYPE_WP_USERS = 'wp_users'; const TYPE_WP_USERS = 'wp_users';
@ -70,7 +74,7 @@ class Segment extends Model {
} }
function withSubscribersCount() { function withSubscribersCount() {
$this->subscribers_count = SubscriberSegment::table_alias('relation') $this->subscribers_count = SubscriberSegment::tableAlias('relation')
->where('relation.segment_id', $this->id) ->where('relation.segment_id', $this->id)
->join( ->join(
MP_SUBSCRIBERS_TABLE, MP_SUBSCRIBERS_TABLE,
@ -186,7 +190,7 @@ class Segment extends Model {
} }
static function getSegmentsForExport() { static function getSegmentsForExport() {
return self::raw_query( return self::rawQuery(
'(SELECT segments.id, segments.name, COUNT(relation.subscriber_id) as subscribers ' . '(SELECT segments.id, segments.name, COUNT(relation.subscriber_id) as subscribers ' .
'FROM ' . MP_SUBSCRIBER_SEGMENT_TABLE . ' relation ' . 'FROM ' . MP_SUBSCRIBER_SEGMENT_TABLE . ' relation ' .
'LEFT JOIN ' . self::$_table . ' segments ON segments.id = relation.segment_id ' . 'LEFT JOIN ' . self::$_table . ' segments ON segments.id = relation.segment_id ' .
@ -249,7 +253,7 @@ class Segment extends Model {
} }
static function getAnalytics() { static function getAnalytics() {
$analytics = Segment::select_expr('type, count(*) as count') $analytics = Segment::selectExpr('type, count(*) as count')
->whereNull('deleted_at') ->whereNull('deleted_at')
->groupBy('type') ->groupBy('type')
->findArray(); ->findArray();

View File

@ -7,6 +7,14 @@ use MailPoet\Tasks\Subscribers as TaskSubscribers;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
/**
* @property int $count_processed
* @property int $count_total
* @property string $newsletter_rendered_body
* @property int $task_id
* @property string|object $meta
* @property string|array $subscribers
*/
class SendingQueue extends Model { class SendingQueue extends Model {
public static $_table = MP_SENDING_QUEUES_TABLE; public static $_table = MP_SENDING_QUEUES_TABLE;
const STATUS_COMPLETED = 'completed'; const STATUS_COMPLETED = 'completed';
@ -151,7 +159,7 @@ class SendingQueue extends Model {
} }
static function getTasks() { static function getTasks() {
return ScheduledTask::table_alias('tasks') return ScheduledTask::tableAlias('tasks')
->selectExpr('tasks.*') ->selectExpr('tasks.*')
->join( ->join(
MP_SENDING_QUEUES_TABLE, MP_SENDING_QUEUES_TABLE,
@ -161,7 +169,7 @@ class SendingQueue extends Model {
} }
static function joinWithTasks() { static function joinWithTasks() {
return static::table_alias('queues') return static::tableAlias('queues')
->join( ->join(
MP_SCHEDULED_TASKS_TABLE, MP_SCHEDULED_TASKS_TABLE,
'tasks.id = queues.task_id', 'tasks.id = queues.task_id',

View File

@ -26,7 +26,7 @@ class StatisticsClicks extends Model {
} }
static function getAllForSubscriber(Subscriber $subscriber) { static function getAllForSubscriber(Subscriber $subscriber) {
return static::table_alias('clicks') return static::tableAlias('clicks')
->select('clicks.id', 'id') ->select('clicks.id', 'id')
->select('newsletter_rendered_subject') ->select('newsletter_rendered_subject')
->select('clicks.created_at', 'created_at') ->select('clicks.created_at', 'created_at')

View File

@ -31,7 +31,7 @@ class StatisticsNewsletters extends Model {
} }
static function getAllForSubscriber(Subscriber $subscriber) { static function getAllForSubscriber(Subscriber $subscriber) {
return static::table_alias('statistics') return static::tableAlias('statistics')
->select('statistics.newsletter_id', 'newsletter_id') ->select('statistics.newsletter_id', 'newsletter_id')
->select('newsletter_rendered_subject') ->select('newsletter_rendered_subject')
->select('opens.created_at', 'opened_at') ->select('opens.created_at', 'opened_at')

View File

@ -10,6 +10,14 @@ use function MailPoet\Util\array_column;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
/**
* @property int $id
* @property string $email
* @property int $wp_user_id
* @property array $segments
* @property array $subscriptions
* @property string $unconfirmed_data
*/
class Subscriber extends Model { class Subscriber extends Model {
public static $_table = MP_SUBSCRIBERS_TABLE; public static $_table = MP_SUBSCRIBERS_TABLE;
@ -373,7 +381,7 @@ class Subscriber extends Model {
} }
static function getSubscribedInSegments($segment_ids) { static function getSubscribedInSegments($segment_ids) {
$subscribers = SubscriberSegment::table_alias('relation') $subscribers = SubscriberSegment::tableAlias('relation')
->whereIn('relation.segment_id', $segment_ids) ->whereIn('relation.segment_id', $segment_ids)
->where('relation.status', 'subscribed') ->where('relation.status', 'subscribed')
->join( ->join(
@ -830,7 +838,7 @@ class Subscriber extends Model {
} }
public function getAllSegmentNamesWithStatus() { public function getAllSegmentNamesWithStatus() {
return Segment::table_alias('segment') return Segment::tableAlias('segment')
->select('name') ->select('name')
->select('subscriber_segment.segment_id', 'segment_id') ->select('subscriber_segment.segment_id', 'segment_id')
->select('subscriber_segment.status', 'status') ->select('subscriber_segment.status', 'status')

View File

@ -14,7 +14,7 @@ class SubscribersFinder {
function findSubscribersInSegments($subscribers_to_process_ids, $newsletter_segments_ids) { function findSubscribersInSegments($subscribers_to_process_ids, $newsletter_segments_ids) {
$result = array(); $result = array();
foreach($newsletter_segments_ids as $segment_id) { foreach($newsletter_segments_ids as $segment_id) {
$segment = Segment::find_one($segment_id); $segment = Segment::findOne($segment_id);
$result = array_merge($result, $this->findSubscribersInSegment($segment, $subscribers_to_process_ids)); $result = array_merge($result, $this->findSubscribersInSegment($segment, $subscribers_to_process_ids));
} }
return $this->unique($result); return $this->unique($result);

View File

@ -111,11 +111,11 @@ class WP {
private static function updateSubscribersEmails() { private static function updateSubscribersEmails() {
global $wpdb; global $wpdb;
Subscriber::raw_execute('SELECT NOW();'); Subscriber::rawExecute('SELECT NOW();');
$start_time = Subscriber::get_last_statement()->fetch(\PDO::FETCH_COLUMN); $start_time = Subscriber::getLastStatement()->fetch(\PDO::FETCH_COLUMN);
$subscribers_table = Subscriber::$_table; $subscribers_table = Subscriber::$_table;
Subscriber::raw_execute(sprintf(' Subscriber::rawExecute(sprintf('
UPDATE IGNORE %1$s UPDATE IGNORE %1$s
INNER JOIN %2$s as wu ON %1$s.wp_user_id = wu.id INNER JOIN %2$s as wu ON %1$s.wp_user_id = wu.id
SET %1$s.email = wu.user_email; SET %1$s.email = wu.user_email;
@ -137,7 +137,7 @@ class WP {
WHERE mps.wp_user_id IS NULL AND %2$s.user_email != "" WHERE mps.wp_user_id IS NULL AND %2$s.user_email != ""
', $subscribers_table, $wpdb->users))->findArray(); ', $subscribers_table, $wpdb->users))->findArray();
Subscriber::raw_execute(sprintf(' Subscriber::rawExecute(sprintf('
INSERT IGNORE INTO %1$s(wp_user_id, email, status, created_at, source) INSERT IGNORE INTO %1$s(wp_user_id, email, status, created_at, source)
SELECT wu.id, wu.user_email, "subscribed", CURRENT_TIMESTAMP(), "%3$s" FROM %2$s wu SELECT wu.id, wu.user_email, "subscribed", CURRENT_TIMESTAMP(), "%3$s" FROM %2$s wu
LEFT JOIN %1$s mps ON wu.id = mps.wp_user_id LEFT JOIN %1$s mps ON wu.id = mps.wp_user_id
@ -151,7 +151,7 @@ class WP {
private static function updateFirstNames() { private static function updateFirstNames() {
global $wpdb; global $wpdb;
$subscribers_table = Subscriber::$_table; $subscribers_table = Subscriber::$_table;
Subscriber::raw_execute(sprintf(' Subscriber::rawExecute(sprintf('
UPDATE %1$s UPDATE %1$s
JOIN %2$s as wpum ON %1$s.wp_user_id = wpum.user_id AND wpum.meta_key = "first_name" JOIN %2$s as wpum ON %1$s.wp_user_id = wpum.user_id AND wpum.meta_key = "first_name"
SET %1$s.first_name = wpum.meta_value SET %1$s.first_name = wpum.meta_value
@ -164,7 +164,7 @@ class WP {
private static function updateLastNames() { private static function updateLastNames() {
global $wpdb; global $wpdb;
$subscribers_table = Subscriber::$_table; $subscribers_table = Subscriber::$_table;
Subscriber::raw_execute(sprintf(' Subscriber::rawExecute(sprintf('
UPDATE %1$s UPDATE %1$s
JOIN %2$s as wpum ON %1$s.wp_user_id = wpum.user_id AND wpum.meta_key = "last_name" JOIN %2$s as wpum ON %1$s.wp_user_id = wpum.user_id AND wpum.meta_key = "last_name"
SET %1$s.last_name = wpum.meta_value SET %1$s.last_name = wpum.meta_value
@ -177,7 +177,7 @@ class WP {
private static function updateFirstNameIfMissing() { private static function updateFirstNameIfMissing() {
global $wpdb; global $wpdb;
$subscribers_table = Subscriber::$_table; $subscribers_table = Subscriber::$_table;
Subscriber::raw_execute(sprintf(' Subscriber::rawExecute(sprintf('
UPDATE %1$s UPDATE %1$s
JOIN %2$s wu ON %1$s.wp_user_id = wu.id JOIN %2$s wu ON %1$s.wp_user_id = wu.id
SET %1$s.first_name = wu.display_name SET %1$s.first_name = wu.display_name
@ -190,7 +190,7 @@ class WP {
$wp_segment = Segment::getWPSegment(); $wp_segment = Segment::getWPSegment();
$subscribers_table = Subscriber::$_table; $subscribers_table = Subscriber::$_table;
$wp_mailpoet_subscriber_segment_table = SubscriberSegment::$_table; $wp_mailpoet_subscriber_segment_table = SubscriberSegment::$_table;
Subscriber::raw_execute(sprintf(' Subscriber::rawExecute(sprintf('
INSERT IGNORE INTO %s(subscriber_id, segment_id, created_at) INSERT IGNORE INTO %s(subscriber_id, segment_id, created_at)
SELECT mps.id, "%s", CURRENT_TIMESTAMP() FROM %s mps SELECT mps.id, "%s", CURRENT_TIMESTAMP() FROM %s mps
WHERE mps.wp_user_id > 0 WHERE mps.wp_user_id > 0
@ -199,7 +199,7 @@ class WP {
private static function removeFromTrash() { private static function removeFromTrash() {
$subscribers_table = Subscriber::$_table; $subscribers_table = Subscriber::$_table;
Subscriber::raw_execute(sprintf(' Subscriber::rawExecute(sprintf('
UPDATE %1$s UPDATE %1$s
SET %1$s.deleted_at = NULL SET %1$s.deleted_at = NULL
WHERE %1$s.wp_user_id IS NOT NULL WHERE %1$s.wp_user_id IS NOT NULL

View File

@ -230,7 +230,7 @@ class Sending {
static function getScheduledQueues($amount = self::RESULT_BATCH_SIZE) { static function getScheduledQueues($amount = self::RESULT_BATCH_SIZE) {
$wp = new WPFunctions(); $wp = new WPFunctions();
$tasks = ScheduledTask::table_alias('tasks') $tasks = ScheduledTask::tableAlias('tasks')
->select('tasks.*') ->select('tasks.*')
->join(SendingQueue::$_table, 'tasks.id = queues.task_id', 'queues') ->join(SendingQueue::$_table, 'tasks.id = queues.task_id', 'queues')
->whereNull('tasks.deleted_at') ->whereNull('tasks.deleted_at')

View File

@ -3,6 +3,9 @@ namespace Sudzy;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
/**
* @method static ORMWrapper|bool create($data=null)
*/
abstract class ValidModel extends \Model { abstract class ValidModel extends \Model {
protected $_validator = null; // Reference to Sudzy validator object protected $_validator = null; // Reference to Sudzy validator object
protected $_validations = array(); // Array of validations protected $_validations = array(); // Array of validations