I have a separate class that establishes PDO connection:
class Core {
public $dbh; // handle of the db connection
private static $instance;
private function __construct() {
// building data source name from config
$dsn = 'mysql:host=' . Config::read('db.host') . ';dbname=' . Config::read('db.basename') . ';port=' . Config::read('db.port') .';charset=' . Config::read('db.charset') . ';connect_timeout=15';
//echo '$dsn is '.$dsn;
// getting DB user from config
$user = Config::read('db.user');
// getting DB password from config
$password = Config::read('db.password');
$this->dbh = new PDO($dsn, $user, $password);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->dbh->exec("set names utf8mb4");
}
public static function getInstance() {
if (!isset(self::$instance)) {
$object = __CLASS__;
self::$instance = new $object;
}
return self::$instance;
}
/** @method PDO */
public function getPdo() {
$core = $this->getInstance();
$pdo = $core->dbh;
return $pdo;
}
}
Now, each time I'm reading from or writing to the db in another class (e. g. $compared_text = Core::getInstance()->getPdo()->query($query_text)->fetchColumn();), even though everything works, PhpStorm says "Referenced method is not found in subject class" regarding the method getPdo().
I googled and came across some answers here on Stackoverflow that suggested using PhpDocs, and, as you can see, I added a comment /** @method PDO */ before the function getPdo(), but it still throws this warning. What's the issue?
UPD
The warning goes away if I write $compared_text = Core::getInstance()->Core::getPdo()->query($query_text)->fetchColumn();.
So now my question is as follows:
Can I make the warning go away without explicitly writing Core:: before calling each method from it? If no, I'm just going to ignore the warning (don't want to disable it though).