Skip to content

Commit

Permalink
Add psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent4vx committed Jun 21, 2021
1 parent 11bb99e commit b639ff0
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Expand Up @@ -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: |
Expand Down
48 changes: 0 additions & 48 deletions build/integration.sh

This file was deleted.

6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -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": {
Expand All @@ -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"
}
}
16 changes: 16 additions & 0 deletions psalm.xml
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
errorLevel="6"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<file name="src/MongoDB/PrimeMongoDbServiceProvider.php" />
</ignoreFiles>
</projectFiles>
</psalm>
19 changes: 14 additions & 5 deletions src/MongoDB/Driver/MongoConnection.php
Expand Up @@ -41,6 +41,7 @@
* Connection for mongoDb
*
* @property Manager $_conn
* @method \Bdf\Prime\Configuration getConfiguration()
*/
class MongoConnection extends Connection implements ConnectionInterface
{
Expand Down Expand Up @@ -104,6 +105,8 @@ public function __construct($params, Driver $driver, Configuration $config = nul
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -237,15 +240,15 @@ 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');
}

/**
* {@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');
}
Expand All @@ -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
Expand Down Expand Up @@ -313,6 +316,8 @@ public function beginTransaction()
}

++$this->transationLevel;

return true;
}

/**
Expand Down Expand Up @@ -352,6 +357,8 @@ public function commit()
}

--$this->transationLevel;

return true;
}

/**
Expand Down Expand Up @@ -382,6 +389,8 @@ public function rollBack()
}

--$this->transationLevel;

return true;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/MongoDB/Driver/MongoDriver.php
Expand Up @@ -13,6 +13,8 @@ class MongoDriver implements Driver
{
/**
* {@inheritdoc}
*
* @psalm-suppress InvalidReturnType
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
Expand All @@ -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);
}

Expand Down
24 changes: 17 additions & 7 deletions src/MongoDB/Driver/MongoPlatform.php
Expand Up @@ -2,6 +2,7 @@

namespace Bdf\Prime\MongoDB\Driver;

use BadMethodCallException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Table;

Expand All @@ -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

Expand All @@ -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');
}

/**
Expand All @@ -93,5 +102,6 @@ public function supportsSavepoints()
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
throw new BadMethodCallException('Not supported');
}
}
2 changes: 2 additions & 0 deletions src/MongoDB/Driver/MongoSchemasManager.php
Expand Up @@ -2,6 +2,7 @@

namespace Bdf\Prime\MongoDB\Driver;

use BadMethodCallException;
use Doctrine\DBAL\Schema\AbstractSchemaManager;

/**
Expand All @@ -23,6 +24,7 @@ class MongoSchemasManager extends AbstractSchemaManager
*/
protected function _getPortableTableColumnDefinition($tableColumn)
{
throw new BadMethodCallException('Not supported');
}
// phpcs:enable

Expand Down
2 changes: 1 addition & 1 deletion src/MongoDB/Driver/ResultSet/CursorResultSet.php
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/MongoDB/Driver/ResultSet/WriteResultSet.php
Expand Up @@ -31,6 +31,7 @@ public function __construct(WriteResult $result)
*/
public function fetchMode($mode, $options = null)
{
return $this;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/Odm/MongoIdGenerator.php
Expand Up @@ -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();
}
}
7 changes: 6 additions & 1 deletion src/MongoDB/Query/Aggregation/Pipeline.php
Expand Up @@ -78,6 +78,8 @@ public function compiler()

/**
* {@inheritdoc}
*
* @param PipelineCompiler $compiler
*/
public function setCompiler(CompilerInterface $compiler)
{
Expand All @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/Query/Aggregation/Stage/StageInterface.php
Expand Up @@ -20,7 +20,7 @@ public function operator();
/**
* Get the stage operations in normalized form
*
* @return array
* @return scalar|array
*/
public function export();

Expand All @@ -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);
}
2 changes: 2 additions & 0 deletions src/MongoDB/Query/Compiled/WriteQuery.php
Expand Up @@ -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) {
Expand Down

0 comments on commit b639ff0

Please sign in to comment.