Skip to content

Commit

Permalink
fixes type linting
Browse files Browse the repository at this point in the history
fixes type linting

fixes type linting

fixes type linting
  • Loading branch information
ffflabs committed May 25, 2020
1 parent 1f03c41 commit 16b6650
Show file tree
Hide file tree
Showing 44 changed files with 283 additions and 2,849 deletions.
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $config->getFinder()
'docs',
'node_modules',
'temp',

'src/router.php',
'vendor',
'.github',
])
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ psalm:
@if [ -f "vendor/bin/psalm" ]; then \
mkdir -p .build/psalm ;\
${MAKE} disable_xdebug --no-print-directory ;\
vendor/bin/psalm --show-info=false \
vendor/bin/psalm --show-info=true \
--config=psalm.xml \
--set-baseline=.build/psalm/psalm-baseline$(FOLDER_BASENAME).xml \
--shepherd $(folder) ;\
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ Other enhancements are in progress and would be a nice to have:
## Requirements

- PHP 7.1+
- PostgreSQL v9+
- ext-psql
- [Composer](https://getcomposer.org/download/)

(If you're using PHP 5.6+, you can still try versions RC2 and below, but you should really, realy upgrade).
(If you're using PostgreSQL 7.4 or 8.x, or PHP 5.6+, you can still try versions RC2 and below, but you should really, realy upgrade).

---

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@
"php -r \"array_map( 'unlink', array_filter((array) glob('temp/twigcache/**/*.php', GLOB_BRACE)));\"",
"php -r \"array_map( 'rmdir', array_filter((array) glob('temp/twigcache/*', GLOB_BRACE)));\""
],
"phpstan": "phpstan analyse src --memory-limit=2G "
"phpstan": "phpstan analyse src "
}
}
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ parameters:
message: "#^Result of method PHPPgAdmin\\\\[a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+\\:\\:[a-zA-Z0-9_]+\\(\\) \\(void\\) is used\\.$#"
path: src/*


-
message: "#^Call to static method br2ln\\(\\) on trait PHPPgAdmin\\Traits\\HelperTrait\\.#"
path: src/*

-
message: "#^Constructor of class [a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+ has an unused parameter \\$[a-zA-Z0-9_]+\\.$#"
path: src/*
Expand Down
19 changes: 19 additions & 0 deletions src/classes/ADONewConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* PHPPgAdmin 6.0.0
*/

namespace PHPPgAdmin;

/**
* @file
* Extends \ADODB_postgres9 to let correct inference on PHPDoc params
*/

/**
* Extends \ADODB_postgres9 to let correct inference on PHPDoc params.
*/
class ADONewConnection extends \ADODB_postgres9
{
}
12 changes: 12 additions & 0 deletions src/classes/ADORecordSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ public function count(): int
{
return $this->NumRows();
}

/**
* Returns the recordCount.
*
* @param int $fieldoffset
*
* @return \ADOFieldObject the field
*/
public function fetchField($fieldoffset = -1): \ADOFieldObject
{
return parent::fetchField();
}
}
9 changes: 7 additions & 2 deletions src/classes/Misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace PHPPgAdmin;

use PHPPgAdmin\Database\Postgres;

/**
* @file
* Class to hold various commonly used functions
Expand Down Expand Up @@ -64,6 +66,9 @@ class Misc

private $_reload_browser = false;

/**
* @var Postgres
*/
private $_data;

private $_database;
Expand Down Expand Up @@ -279,9 +284,9 @@ public function getErrorMsg()
*
* @internal mixed $plaform placeholder that will receive the value of the platform
*
* @return null|\PHPPgAdmin\Database\ADOdbBase the database accessor instance
* @return null|\PHPPgAdmin\Database\Postgres the database accessor instance
*/
public function getDatabaseAccessor($database = '', $server_id = null): ?\PHPPgAdmin\Database\ADOdbBase
public function getDatabaseAccessor($database = '', $server_id = null): ?\PHPPgAdmin\Database\Postgres
{
$lang = $this->lang;

Expand Down
7 changes: 6 additions & 1 deletion src/classes/ViewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class ViewManager extends \Slim\Views\Twig

public $view;

/**
* @var \PHPPgAdmin\Misc
*/
public $misc;

protected $container;

private $_connection;
Expand Down Expand Up @@ -101,7 +106,7 @@ public function __construct($path, $settings, \Slim\Container $c)

$this->addExtension(new \Slim\Views\TwigExtension($c['router'], $basePath));

$this->offsetSet('subfolder', $c->subfolder);
$this->offsetSet('subfolder', self::SUBFOLDER);
$this->offsetSet('theme', $this->misc->getConf('theme'));
$this->offsetSet('Favicon', $this->icon('Favicon'));
$this->offsetSet('Introduction', $this->icon('Introduction'));
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/DataimportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function render()
/**
* Character data handler for XML import feature.
*
* @param $parser
* @param $cdata
* @param resource $parser
* @param string $cdata
*/
$_charHandler = static function ($parser, $cdata) use (&$state, &$curr_col_val): void {
if ('COLUMN' === $state) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function adjustTabsForTree(&$tabs)
* 'nodata' - message to display when node has no children
* @param bool $print either to return or echo the result
*
* @return \Slim\Http\Response|string the json rendered tree
* @return array<int|string, array<string, mixed>|bool|string> the json rendered tree
*/
private function printTreeJSON(&$treedata, &$attrs, $print = true)
{
Expand Down
15 changes: 8 additions & 7 deletions src/database/ADOdbBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace PHPPgAdmin\Database;

use PHPPgAdmin\ADONewConnection;

/**
* @file
* Parent class of all ADODB objects.
Expand All @@ -28,7 +30,7 @@ class ADOdbBase
/**
* Base constructor.
*
* @param \ADODB_postgres9 $conn The connection object
* @param ADONewConnection $conn The connection object
* @param mixed $container
* @param mixed $server_info
*/
Expand All @@ -40,7 +42,7 @@ public function __construct(&$conn, $container, $server_info)
$this->lang = $container->get('lang');
$this->conf = $container->get('conf');

//$this->prtrace('instanced connection class');
$this->prtrace('instanced connection class');
$this->conn = $conn;
}

Expand All @@ -55,7 +57,7 @@ public function __construct(&$conn, $container, $server_info)
* @param string $comment the comment to add
* @param null|string $basetype
*
* @return \ADORecordSet|int recordset of results or error code
* @return int|\PHPPgAdmin\ADORecordSet recordset of results or error code
*/
public function setComment($obj_type, $obj_name, $table, $comment, $basetype = null)
{
Expand Down Expand Up @@ -174,8 +176,7 @@ public function arrayClean(&$arr)
*
* @param string $sql The SQL query to execute
*
* @return \ADORecordSet|int A recordset or an error code
* (However, error code 0 means success WTF)
* @return int|\PHPPgAdmin\ADORecordSet A recordset or an error code
*/
public function execute($sql)
{
Expand Down Expand Up @@ -203,7 +204,7 @@ public function close(): void
*
* @param string $sql The SQL statement to be executed
*
* @return \ADORecordSet|int A recordset or an error number
* @return int|\PHPPgAdmin\ADORecordSet A recordset or an error number
*/
public function selectSet($sql)
{
Expand Down Expand Up @@ -506,7 +507,7 @@ public function getPlatform()
try {
return $this->conn->platform;
} catch (\Exception $e) {
//$this->prtrace($e->getMessage());
$this->prtrace($e->getMessage());

return 'UNKNOWN';
}
Expand Down
11 changes: 7 additions & 4 deletions src/database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct($server_info, $database, $container, $fetchMode = AD

$this->container = $container;

$this->conn = \ADONewConnection('postgres9');
$this->conn = ADONewConnection('postgres9');
//$this->conn->debug = true;
$this->conn->setFetchMode($fetchMode);

Expand All @@ -93,14 +93,15 @@ public function __construct($server_info, $database, $container, $fetchMode = AD

/*try {
$this->_connection_result = $this->conn->connect($pghost, $user, $password, $database);
//$this->prtrace(['_connection_result' => $this->_connection_result, 'conn' => $this->conn]);
$this->prtrace(['_connection_result' => $this->_connection_result, 'conn' => $this->conn]);
} catch (\PHPPgAdmin\ADOdbException $e) {
//$this->prtrace(['message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
$this->prtrace(['message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
*/
try {
$this->conn->connect($pghost, $user, $password, $database);
//$this->prtrace($this->conn);
} catch (\Exception $e) {
//$this->prtrace($e->getMessage(), $e->getTrace());
$this->prtrace($e->getMessage(), $e->getTrace());
}
}

Expand Down Expand Up @@ -157,6 +158,8 @@ public function getDriver(&$description)
} else {
$major_version = \implode('.', [$version_parts[0], $version_parts[1]]);
}

//$this->prtrace(['pg_version' => pg_version($this->conn->_connectionID), 'version' => $version, 'major_version' => $major_version]);
// Detect version and choose appropriate database driver
if (\array_key_exists($major_version, $this->version_dictionary)) {
return $this->version_dictionary[$major_version];
Expand Down
28 changes: 15 additions & 13 deletions src/database/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Postgres extends ADOdbBase

public function __construct(&$conn, $container, $server_info)
{
//$this->prtrace('major_version :' . $this->major_version);
$this->conn = $conn;
$this->container = $container;

Expand Down Expand Up @@ -182,7 +183,7 @@ public function printField($name, $value, $type, $extras = []): void
* @param string $term The search term
* @param string $filter The object type to restrict to ('' means no restriction)
*
* @return \ADORecordSet|int A recordset
* @return int|\PHPPgAdmin\ADORecordSet A recordset
*/
public function findObject($term, $filter)
{
Expand Down Expand Up @@ -382,7 +383,7 @@ public function getAttributeNames($table, $atts)
*
* @param bool $all True to get all languages, regardless of show_system
*
* @return \ADORecordSet|int A recordset
* @return int|\PHPPgAdmin\ADORecordSet A recordset
*/
public function getLanguages($all = false)
{
Expand Down Expand Up @@ -473,7 +474,7 @@ public function executeScript($name, $callback = null)
for ($i = 0; $i < $len; $this->advance_1($i, $prevlen, $thislen)) {
/* was the previous character a backslash? */
if (0 < $i && '\\' === \mb_substr($line, $i - $prevlen, 1)) {
//$this->prtrace('bslash_count', $bslash_count, $line);
$this->prtrace('bslash_count', $bslash_count, $line);
++$bslash_count;
} else {
$bslash_count = 0;
Expand All @@ -487,6 +488,7 @@ public function executeScript($name, $callback = null)

/* in quote? */
if (0 !== $in_quote) {
//$this->prtrace('in_quote', $in_quote, $line);
/*
* end of quote if matching non-backslashed character.
* backslashes don't count for double quotes, though.
Expand All @@ -497,7 +499,7 @@ public function executeScript($name, $callback = null)
$in_quote = 0;
}
} elseif ($dol_quote) {
//$this->prtrace('dol_quote', $dol_quote, $line);
$this->prtrace('dol_quote', $dol_quote, $line);

if (0 === \strncmp(\mb_substr($line, $i), $dol_quote, \mb_strlen($dol_quote))) {
$this->advance_1($i, $prevlen, $thislen);
Expand All @@ -509,7 +511,7 @@ public function executeScript($name, $callback = null)
$dol_quote = '';
}
} elseif ('/*' === \mb_substr($line, $i, 2)) {
//$this->prtrace('open_xcomment', $in_xcomment, $line, $i, $prevlen, $thislen);
$this->prtrace('open_xcomment', $in_xcomment, $line, $i, $prevlen, $thislen);

if (0 === $in_xcomment) {
++$in_xcomment;
Expand Down Expand Up @@ -695,12 +697,12 @@ public function executeScript($name, $callback = null)
* @param null|int $page_size The number of rows per page
* @param int $max_pages (return-by-ref) The max number of pages in the relation
*
* @return \ADORecordSet|int A recordset on success or an int with error code
* - -1 transaction error
* - -2 counting error
* - -3 page or page_size invalid
* - -4 unknown type
* - -5 failed setting transaction read only
* @return int|\PHPPgAdmin\ADORecordSet A recordset on success or an int with error code
* - -1 transaction error
* - -2 counting error
* - -3 page or page_size invalid
* - -4 unknown type
* - -5 failed setting transaction read only
*/
public function browseQuery($type, $table, $query, $sortkey, $sortdir, $page, $page_size, &$max_pages)
{
Expand Down Expand Up @@ -742,7 +744,7 @@ public function browseQuery($type, $table, $query, $sortkey, $sortdir, $page, $p
// Open a transaction
$status = $this->beginTransaction();

if (false !== $status) {
if (0 !== $status) {
return -1;
}

Expand Down Expand Up @@ -802,7 +804,7 @@ public function browseQuery($type, $table, $query, $sortkey, $sortdir, $page, $p
$rs = $this->selectSet("SELECT * FROM ({$query}) AS sub {$orderby} LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
$status = $this->endTransaction();

if (false !== $status) {
if (0 !== $status) {
$this->rollbackTransaction();

return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/database/Postgres10.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Postgres10 extends Postgres96
/**
* Return all tables in current database (and schema).
*
* @return \ADORecordSet|int All tables, sorted alphabetically
* @return int|\PHPPgAdmin\ADORecordSet All tables, sorted alphabetically
*/
public function getTables()
{
Expand Down
2 changes: 1 addition & 1 deletion src/database/Postgres11.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Postgres11 extends Postgres10
* @param bool $all If true, will find all available functions, if false just those in search path
* @param mixed $type If truthy, will return functions of type trigger
*
* @return \ADORecordSet|int All functions
* @return int|\PHPPgAdmin\ADORecordSet All functions
*/
public function getFunctions($all = false, $type = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/database/Postgres12.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Postgres12 extends Postgres11
*
* @param string $table The table name
*
* @return bool false
* @return bool
*/
public function hasObjectID($table)
{
Expand Down
Loading

0 comments on commit 16b6650

Please sign in to comment.