diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index 4ac237d..7a7a2d4 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -80,8 +80,8 @@ jobs:
- name: Run PHPCS
run: composer run-script phpcs
-# - name: Run type coverage
-# run: composer run-script psalm
+ - name: Run type coverage
+ run: composer run-script psalm
# - name: Run Infection
# run: |
diff --git a/build/integration.sh b/build/integration.sh
deleted file mode 100755
index 10c5128..0000000
--- a/build/integration.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/bash
-
-source $(dirname $(readlink -f $0))/ci-functions.sh
-
-srcdir=${1:-/home/bdf-prime-mongodb}
-
-export APPLICATION_ENV=integration
-export SERVER_DB_PROFILE=integration
-export APP_PATH=${srcdir}
-export VERSION=$(cat ${srcdir}/release.txt)
-export WORKSPACE=/var/lib/jenkins/workspace/bdf-prime-mongodb
-
-mongodb=0
-
-echo
-echo "********************************************************************************"
-echo "**************************** Setup ****************************"
-echo "********************************************************************************"
-echo
-
-run-configure ${srcdir} 'update'
-
-echo
-echo "********************************************************************************"
-echo "************************** Continous integration **************************"
-echo "********************************************************************************"
-echo
-
-targetdir="src"
-run-phpunit ${srcdir} api 1 --exclude-group=dev
-retval=$?
-[ $retval -ne 0 ] && touch ${srcdir}/build/reports/__failure
-[ -f ${srcdir}/build/reports/__failure ] || run-phpcpd ${srcdir} ${targetdir}
-[ -f ${srcdir}/build/reports/__failure ] || run-pdepend ${srcdir} ${targetdir}
-[ -f ${srcdir}/build/reports/__failure ] || run-phpcs ${srcdir} ${targetdir}
-#[ -f ${srcdir}/build/reports/__failure ] || run-phpdoc ${srcdir} --directory ${targetdir}
-change-source-path ${srcdir}
-
-echo
-echo "********************************************************************************"
-echo "**************************** Shutdown ****************************"
-echo "********************************************************************************"
-echo
-kill $mongodb 1>/dev/null 2>&1
-sleep 15
-kill -9 $mongodb 1>/dev/null 2>&1
-
-exit 0
diff --git a/composer.json b/composer.json
index 5862c44..772ba6d 100755
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,8 @@
},
"require-dev": {
"phpunit/phpunit": "~7.5",
- "squizlabs/php_codesniffer": "~3.0"
+ "squizlabs/php_codesniffer": "~3.0",
+ "vimeo/psalm": "~4.0"
},
"extra": {
"branch-alias": {
@@ -26,6 +27,7 @@
"scripts": {
"tests": "phpunit",
"tests-with-coverage": "phpunit --coverage-clover coverage.xml",
- "phpcs": "phpcs --standard=psr12 --tab-width=4 --exclude=Generic.Files.LineLength src/"
+ "phpcs": "phpcs --standard=psr12 --tab-width=4 --exclude=Generic.Files.LineLength src/",
+ "psalm": "psalm --shepherd"
}
}
diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..16b39be
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/MongoDB/Driver/MongoConnection.php b/src/MongoDB/Driver/MongoConnection.php
index 2c2aafc..4829c8c 100644
--- a/src/MongoDB/Driver/MongoConnection.php
+++ b/src/MongoDB/Driver/MongoConnection.php
@@ -41,6 +41,7 @@
* Connection for mongoDb
*
* @property Manager $_conn
+ * @method \Bdf\Prime\Configuration getConfiguration()
*/
class MongoConnection extends Connection implements ConnectionInterface
{
@@ -104,6 +105,8 @@ public function __construct($params, Driver $driver, Configuration $config = nul
public function setName($name)
{
$this->name = $name;
+
+ return $this;
}
/**
@@ -176,9 +179,9 @@ public function select($query, array $bindings = [], array $types = [])
/**
* {@inheritdoc}
*/
- public function insert($tableExpression, array $data, array $types = [])
+ public function insert($table, array $data, array $types = [])
{
- return $this->builder()->from($tableExpression)->insert($data);
+ return $this->builder()->from($table)->insert($data);
}
/**
@@ -237,7 +240,7 @@ public function executeWrite($collection, BulkWrite $query)
/**
* {@inheritdoc}
*/
- public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null)
+ public function executeQuery($sql, array $params = [], $types = [], QueryCacheProfile $qcp = null)
{
throw new \BadMethodCallException('Method ' . __METHOD__ . ' cannot be called on mongoDB connection');
}
@@ -245,7 +248,7 @@ public function executeQuery($query, array $params = [], $types = [], QueryCache
/**
* {@inheritdoc}
*/
- public function executeUpdate($query, array $params = [], array $types = [])
+ public function executeUpdate($sql, array $params = [], array $types = [])
{
throw new \BadMethodCallException('Method ' . __METHOD__ . ' cannot be called on mongoDB connection');
}
@@ -271,7 +274,7 @@ public function runCommand($command, $arguments = 1)
/**
* Run a command
*
- * @param string|array|Command $command
+ * @param string|array|Command|CommandInterface $command
* @param mixed $arguments
*
* @return \MongoDB\Driver\Cursor
@@ -313,6 +316,8 @@ public function beginTransaction()
}
++$this->transationLevel;
+
+ return true;
}
/**
@@ -352,6 +357,8 @@ public function commit()
}
--$this->transationLevel;
+
+ return true;
}
/**
@@ -382,6 +389,8 @@ public function rollBack()
}
--$this->transationLevel;
+
+ return true;
}
/**
diff --git a/src/MongoDB/Driver/MongoDriver.php b/src/MongoDB/Driver/MongoDriver.php
index f8c1867..78bbf1a 100644
--- a/src/MongoDB/Driver/MongoDriver.php
+++ b/src/MongoDB/Driver/MongoDriver.php
@@ -13,6 +13,8 @@ class MongoDriver implements Driver
{
/**
* {@inheritdoc}
+ *
+ * @psalm-suppress InvalidReturnType
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
@@ -28,6 +30,7 @@ public function connect(array $params, $username = null, $password = null, array
unset($params['username'], $params['password']);
}
+ /** @psalm-suppress InvalidReturnStatement */
return new Manager($this->buildDsn($params), array_filter($params), $driverOptions);
}
diff --git a/src/MongoDB/Driver/MongoPlatform.php b/src/MongoDB/Driver/MongoPlatform.php
index 869a6ad..71718b1 100644
--- a/src/MongoDB/Driver/MongoPlatform.php
+++ b/src/MongoDB/Driver/MongoPlatform.php
@@ -2,6 +2,7 @@
namespace Bdf\Prime\MongoDB\Driver;
+use BadMethodCallException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Table;
@@ -17,37 +18,42 @@ class MongoPlatform extends AbstractPlatform
/**
* {@inheritdoc}
*/
- public function getBooleanTypeDeclarationSQL(array $columnDef)
+ public function getBooleanTypeDeclarationSQL(array $column)
{
+ throw new BadMethodCallException('Not supported');
}
/**
* {@inheritdoc}
*/
- public function getIntegerTypeDeclarationSQL(array $columnDef)
+ public function getIntegerTypeDeclarationSQL(array $column)
{
+ throw new BadMethodCallException('Not supported');
}
/**
* {@inheritdoc}
*/
- public function getBigIntTypeDeclarationSQL(array $columnDef)
+ public function getBigIntTypeDeclarationSQL(array $column)
{
+ throw new BadMethodCallException('Not supported');
}
/**
* {@inheritdoc}
*/
- public function getSmallIntTypeDeclarationSQL(array $columnDef)
+ public function getSmallIntTypeDeclarationSQL(array $column)
{
+ throw new BadMethodCallException('Not supported');
}
// phpcs:disable
/**
* {@inheritdoc}
*/
- protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
+ protected function _getCommonIntegerTypeDeclarationSQL(array $column)
{
+ throw new BadMethodCallException('Not supported');
}
// phpcs:enable
@@ -56,20 +62,23 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
*/
protected function initializeDoctrineTypeMappings()
{
+ throw new BadMethodCallException('Not supported');
}
/**
* {@inheritdoc}
*/
- public function getClobTypeDeclarationSQL(array $field)
+ public function getClobTypeDeclarationSQL(array $column)
{
+ throw new BadMethodCallException('Not supported');
}
/**
* {@inheritdoc}
*/
- public function getBlobTypeDeclarationSQL(array $field)
+ public function getBlobTypeDeclarationSQL(array $column)
{
+ throw new BadMethodCallException('Not supported');
}
/**
@@ -93,5 +102,6 @@ public function supportsSavepoints()
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
+ throw new BadMethodCallException('Not supported');
}
}
diff --git a/src/MongoDB/Driver/MongoSchemasManager.php b/src/MongoDB/Driver/MongoSchemasManager.php
index de6a8e0..053b137 100644
--- a/src/MongoDB/Driver/MongoSchemasManager.php
+++ b/src/MongoDB/Driver/MongoSchemasManager.php
@@ -2,6 +2,7 @@
namespace Bdf\Prime\MongoDB\Driver;
+use BadMethodCallException;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
/**
@@ -23,6 +24,7 @@ class MongoSchemasManager extends AbstractSchemaManager
*/
protected function _getPortableTableColumnDefinition($tableColumn)
{
+ throw new BadMethodCallException('Not supported');
}
// phpcs:enable
diff --git a/src/MongoDB/Driver/ResultSet/CursorResultSet.php b/src/MongoDB/Driver/ResultSet/CursorResultSet.php
index b064811..b1f6972 100644
--- a/src/MongoDB/Driver/ResultSet/CursorResultSet.php
+++ b/src/MongoDB/Driver/ResultSet/CursorResultSet.php
@@ -63,7 +63,7 @@ public function fetchMode($mode, $options = null)
break;
case self::FETCH_CLASS:
- if (is_subclass_of($options, Unserializable::class)) {
+ if ($options && is_subclass_of($options, Unserializable::class)) {
$this->cursor->setTypeMap(['root' => $options]);
break;
}
diff --git a/src/MongoDB/Driver/ResultSet/WriteResultSet.php b/src/MongoDB/Driver/ResultSet/WriteResultSet.php
index 2267267..7a8d4a0 100644
--- a/src/MongoDB/Driver/ResultSet/WriteResultSet.php
+++ b/src/MongoDB/Driver/ResultSet/WriteResultSet.php
@@ -31,6 +31,7 @@ public function __construct(WriteResult $result)
*/
public function fetchMode($mode, $options = null)
{
+ return $this;
}
/**
diff --git a/src/MongoDB/Odm/MongoIdGenerator.php b/src/MongoDB/Odm/MongoIdGenerator.php
index 2d33868..56e75ae 100644
--- a/src/MongoDB/Odm/MongoIdGenerator.php
+++ b/src/MongoDB/Odm/MongoIdGenerator.php
@@ -14,8 +14,8 @@ class MongoIdGenerator extends AbstractGenerator
/**
* {@inheritdoc}
*/
- protected function doGenerate($primary, array &$data, ServiceLocator $serviceLocator)
+ protected function doGenerate($property, array &$data, ServiceLocator $serviceLocator)
{
- return $data[$primary] = new ObjectID();
+ return $data[$property] = new ObjectID();
}
}
diff --git a/src/MongoDB/Query/Aggregation/Pipeline.php b/src/MongoDB/Query/Aggregation/Pipeline.php
index 98c17e3..c61106e 100644
--- a/src/MongoDB/Query/Aggregation/Pipeline.php
+++ b/src/MongoDB/Query/Aggregation/Pipeline.php
@@ -78,6 +78,8 @@ public function compiler()
/**
* {@inheritdoc}
+ *
+ * @param PipelineCompiler $compiler
*/
public function setCompiler(CompilerInterface $compiler)
{
@@ -100,7 +102,10 @@ public function connection()
public function on(ConnectionInterface $connection)
{
$this->connection = $connection;
- $this->compiler = $connection->factory()->compiler(static::class);
+ /** @var PipelineCompiler */
+ $this->compiler = $connection->factory()->compiler(static::class);
+
+ return $this;
}
/**
diff --git a/src/MongoDB/Query/Aggregation/Stage/StageInterface.php b/src/MongoDB/Query/Aggregation/Stage/StageInterface.php
index 9d0d037..b090eb4 100644
--- a/src/MongoDB/Query/Aggregation/Stage/StageInterface.php
+++ b/src/MongoDB/Query/Aggregation/Stage/StageInterface.php
@@ -20,7 +20,7 @@ public function operator();
/**
* Get the stage operations in normalized form
*
- * @return array
+ * @return scalar|array
*/
public function export();
@@ -30,7 +30,7 @@ public function export();
* @param CompilableClause $clause
* @param MongoGrammar $grammar
*
- * @return array
+ * @return scalar|array
*/
public function compile(CompilableClause $clause, MongoGrammar $grammar);
}
diff --git a/src/MongoDB/Query/Compiled/WriteQuery.php b/src/MongoDB/Query/Compiled/WriteQuery.php
index f76fa56..2ecb428 100644
--- a/src/MongoDB/Query/Compiled/WriteQuery.php
+++ b/src/MongoDB/Query/Compiled/WriteQuery.php
@@ -168,6 +168,8 @@ public function merge(WriteQuery $query)
*/
public function execute(MongoConnection $connection)
{
+ // Psalm do not detect correct constructor signature
+ /** @psalm-suppress InvalidArgument */
$bulk = new BulkWrite($this->options);
foreach ($this->inserts as $insert) {
diff --git a/src/MongoDB/Query/Compiler/MongoGrammar.php b/src/MongoDB/Query/Compiler/MongoGrammar.php
index 87585ef..0822ad5 100644
--- a/src/MongoDB/Query/Compiler/MongoGrammar.php
+++ b/src/MongoDB/Query/Compiler/MongoGrammar.php
@@ -2,6 +2,7 @@
namespace Bdf\Prime\MongoDB\Query\Compiler;
+use BadMethodCallException;
use Bdf\Prime\Platform\PlatformInterface;
use Bdf\Prime\Query\CompilableClause;
use Bdf\Prime\Query\Compiler\CompilerInterface;
@@ -58,21 +59,27 @@ public function __construct(PlatformInterface $platform)
// Add compiler methods for compatibility with ExpressionTransformerInterface::setContext()
public function compileInsert(CompilableClause $query)
{
+ throw new BadMethodCallException('Not supported');
}
public function compileUpdate(CompilableClause $query)
{
+ throw new BadMethodCallException('Not supported');
}
public function compileDelete(CompilableClause $query)
{
+ throw new BadMethodCallException('Not supported');
}
public function compileSelect(CompilableClause $query)
{
+ throw new BadMethodCallException('Not supported');
}
public function quoteIdentifier(CompilableClause $query, $column)
{
+ throw new BadMethodCallException('Not supported');
}
public function getBindings(CompilableClause $query)
{
+ throw new BadMethodCallException('Not supported');
}
/**
@@ -146,7 +153,7 @@ public function expression(CompilableClause $query, $expression)
* @param CompilableClause $query The query container
* @param array $columns The columns (or expressions) to project
*
- * @return array
+ * @return array
*
* @see https://docs.mongodb.com/manual/reference/method/db.collection.find/#projection For find projection
* @see https://docs.mongodb.com/v3.2/reference/operator/aggregation/project/ For aggregation operation
diff --git a/src/MongoDB/Query/MongoKeyValueQuery.php b/src/MongoDB/Query/MongoKeyValueQuery.php
index 48d3557..a8b57f6 100644
--- a/src/MongoDB/Query/MongoKeyValueQuery.php
+++ b/src/MongoDB/Query/MongoKeyValueQuery.php
@@ -57,11 +57,11 @@ public function __construct(ConnectionInterface $connection, PreprocessorInterfa
/**
* {@inheritdoc}
*/
- public function from($table, $alias = null)
+ public function from($from, $alias = null)
{
- if ($this->statements['collection'] !== $table) {
+ if ($this->statements['collection'] !== $from) {
$this->compilerState->invalidate();
- $this->statements['collection'] = $table;
+ $this->statements['collection'] = $from;
}
return $this;
@@ -141,17 +141,25 @@ public function avg($column = null)
/**
* {@inheritdoc}
+ *
+ * @psalm-suppress InvalidReturnType
+ * @todo remove psalm-suppress when prime types will be fixed
*/
public function min($column = null)
{
+ /** @psalm-suppress InvalidReturnStatement */
return $this->aggregate(__FUNCTION__, $column);
}
/**
* {@inheritdoc}
+ *
+ * @psalm-suppress InvalidReturnType
+ * @todo remove psalm-suppress when prime types will be fixed
*/
public function max($column = null)
{
+ /** @psalm-suppress InvalidReturnStatement */
return $this->aggregate(__FUNCTION__, $column);
}
diff --git a/src/MongoDB/Query/MongoQuery.php b/src/MongoDB/Query/MongoQuery.php
index a31a02b..5f1e3c1 100644
--- a/src/MongoDB/Query/MongoQuery.php
+++ b/src/MongoDB/Query/MongoQuery.php
@@ -178,7 +178,7 @@ public function mul($attribute, $number)
/**
* {@inheritdoc}
*/
- public function paginationCount($columns = null)
+ public function paginationCount($column = null)
{
$statements = $this->statements;
@@ -186,7 +186,7 @@ public function paginationCount($columns = null)
$this->statements['limit'] = null;
$this->statements['offset'] = null;
- return $this->count($columns);
+ return $this->count($column);
} finally {
$this->statements = $statements;
}
@@ -207,22 +207,30 @@ public function count($column = null)
*/
public function avg($column = null)
{
- return $this->aggregate(__FUNCTION__, $column);
+ return (float) $this->aggregate(__FUNCTION__, $column);
}
/**
* {@inheritdoc}
+ *
+ * @psalm-suppress InvalidReturnType
+ * @todo remove psalm-suppress when prime types will be fixed
*/
public function min($column = null)
{
+ /** @psalm-suppress InvalidReturnStatement */
return $this->aggregate(__FUNCTION__, $column);
}
/**
* {@inheritdoc}
+ *
+ * @psalm-suppress InvalidReturnType
+ * @todo remove psalm-suppress when prime types will be fixed
*/
public function max($column = null)
{
+ /** @psalm-suppress InvalidReturnStatement */
return $this->aggregate(__FUNCTION__, $column);
}
@@ -231,7 +239,7 @@ public function max($column = null)
*/
public function sum($column = null)
{
- return $this->aggregate(__FUNCTION__, $column);
+ return (float) $this->aggregate(__FUNCTION__, $column);
}
/**
diff --git a/src/MongoDB/Schema/IndexSetDiff.php b/src/MongoDB/Schema/IndexSetDiff.php
index b662414..bd2a4d2 100644
--- a/src/MongoDB/Schema/IndexSetDiff.php
+++ b/src/MongoDB/Schema/IndexSetDiff.php
@@ -2,6 +2,7 @@
namespace Bdf\Prime\MongoDB\Schema;
+use Bdf\Prime\MongoDB\Query\Command\CommandInterface;
use Bdf\Prime\MongoDB\Query\Command\CreateIndexes;
use Bdf\Prime\MongoDB\Query\Command\DropIndexes;
use Bdf\Prime\Schema\Comparator\IndexSetComparatorInterface;
@@ -69,7 +70,7 @@ public function commands()
}
/**
- * @return Command[]
+ * @return CommandInterface[]
*/
protected function removeCommands()
{
@@ -90,7 +91,7 @@ protected function removeCommands()
}
/**
- * @return Command[]
+ * @return CommandInterface[]
*/
protected function createCommands()
{
diff --git a/src/MongoDB/Schema/MongoSchemaManager.php b/src/MongoDB/Schema/MongoSchemaManager.php
index 1b0e6f5..60400e6 100644
--- a/src/MongoDB/Schema/MongoSchemaManager.php
+++ b/src/MongoDB/Schema/MongoSchemaManager.php
@@ -53,6 +53,8 @@ public function flush()
}
$this->pending = [];
+
+ return true;
}
/**
@@ -65,6 +67,10 @@ public function pending()
/**
* {@inheritdoc}
+ *
+ * @param TableInterface[] $tables
+ *
+ * @psalm-suppress InvalidReturnType
*/
public function schema($tables = [])
{
@@ -72,6 +78,7 @@ public function schema($tables = [])
$tables = [$tables];
}
+ /** @psalm-suppress InvalidReturnStatement */
return new SchemaCreation($tables);
}