Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@ on:
pull_request:
branches:
- main

jobs:
php-cs-fixer:
name: "Lint & Analyse"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Setup the correct PHP version globally
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3.16'

- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- uses: php-actions/composer@v6
with:
progress: yes
php_version: 8.3
php_version: 8.3.16
version: 2

- name: "PHP-CS-Fixer"
run: vendor/bin/php-cs-fixer fix --dry-run

- name: "PSalm"
run: vendor/bin/psalm --show-info=true
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: "Running Unit Tests"
strategy:
matrix:
php: ['8.1', '8.2', '8.3']
php: ['8.1.31', '8.2.27', '8.3.16']

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 0 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
MultilineCommentOpeningClosingAloneFixer::name() => true,
MultilinePromotedPropertiesFixer::name() => true,
PhpUnitAssertArgumentsOrderFixer::name() => true,
PhpdocNoSuperfluousParamFixer::name() => true,
PhpdocParamOrderFixer::name() => true,
StringableInterfaceFixer::name() => true,
])
Expand Down
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,16 @@ composer require nyholm/psr7 nyholm/psr7-server kriswallsmith/buzz

## Result formats/hydration

In order to make the results of the bolt protocol and the http uniform, the driver provides result formatters (aka hydrators). The client is configurable with these formatters. You can even implement your own.
In order to make the results of the bolt protocol and the http uniform, the driver provides and summarizes the results.

The default formatter is the `\Laudis\Neo4j\Formatters\OGMFormatter`, which is explained extensively in [the result format section](#accessing-the-results).
The default formatter is the `\Laudis\Neo4j\Formatters\SummarizedResultFormatter`, which is explained extensively in [the result format section](#accessing-the-results).

The driver provides three formatters by default, which are all found in the Formatter namespace:
- `\Laudis\Neo4j\Formatter\BasicFormatter` which erases all the Cypher types and simply returns every value in the resulting map as a [scalar](https://www.php.net/manual/en/function.is-scalar.php), null or array value.
- `\Laudis\Neo4j\Formatter\OGMFormatter` which maps the cypher types to php types as explained [here](#accessing-the-results).
- `\Laudis\Neo4j\Formatter\SummarizedResultFormatter` which decorates any formatter and adds an extensive result summary.
`\Laudis\Neo4j\Formatter\SummarizedResultFormatter` adds an extensive result summary.

The client builder provides an easy way to change the formatter:

```php
$client = \Laudis\Neo4j\ClientBuilder::create()
->withFormatter(\Laudis\Neo4j\Formatter\SummarizedResultFormatter::create())
->build();
$client = \Laudis\Neo4j\ClientBuilder::create()->build();

/**
* The client will now return a result, decorated with a summary.
Expand All @@ -339,8 +334,6 @@ $summary = $summarisedResult->getSummary();
$result = $summarisedResult->getResult();
```

In order to use a custom formatter, implement the `Laudis\Neo4j\Contracts\FormatterInterface` and provide it when using the client builder.

## Concepts

The driver API described [here](https://neo4j.com/docs/driver-manual/current/) is the main target of the driver. Because of this, the client is nothing more than a driver manager. The driver creates sessions. A session runs queries through a transaction.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
"nyholm/psr7": "^1.3",
"nyholm/psr7-server": "^1.0",
"kriswallsmith/buzz": "^1.2",
"vimeo/psalm": "^5.0",
"friendsofphp/php-cs-fixer": "3.15.0",
"psalm/plugin-phpunit": "^0.18",
"vimeo/psalm": "^6.5",
"friendsofphp/php-cs-fixer": "3.68.5",
"psalm/plugin-phpunit": "^0.19",
"monolog/monolog": "^2.2",
"symfony/uid": "^5.0",
"symfony/var-dumper": "^5.0",
Expand Down
12 changes: 0 additions & 12 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@
<directory name="src"/>
</errorLevel>
</UnusedForeachValue>
<DeprecatedClass>
<errorLevel type="suppress">
<directory name="tests"/>
<directory name="src"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedInterface>
<errorLevel type="suppress">
<directory name="tests"/>
<directory name="src"/>
</errorLevel>
</DeprecatedInterface>
<MissingConstructor>
<errorLevel type="suppress">
<directory name="tests"/>
Expand Down
3 changes: 2 additions & 1 deletion src/Authentication/BasicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function __construct(
private readonly string $username,
private readonly string $password,
private readonly ?Neo4jLogger $logger,
) {}
) {
}

/**
* @throws Exception
Expand Down
4 changes: 3 additions & 1 deletion src/Authentication/KerberosAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ final class KerberosAuth implements AuthenticateInterface
public function __construct(
private readonly string $token,
private readonly ?Neo4jLogger $logger,
) {}
) {
}

public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
{
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using KerberosAuth');

/**
* @psalm-suppress ImpureMethodCall Request is a pure object:
*
Expand Down
6 changes: 4 additions & 2 deletions src/Authentication/NoAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ final class NoAuth implements AuthenticateInterface
* @pure
*/
public function __construct(
private readonly ?Neo4jLogger $logger
) {}
private readonly ?Neo4jLogger $logger,
) {
}

public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
{
$this->logger?->log(LogLevel::DEBUG, 'Authentication disabled');

/**
* @psalm-suppress ImpureMethodCall Request is a pure object:
*
Expand Down
6 changes: 4 additions & 2 deletions src/Authentication/OpenIDConnectAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ final class OpenIDConnectAuth implements AuthenticateInterface
*/
public function __construct(
private readonly string $token,
private readonly ?Neo4jLogger $logger
) {}
private readonly ?Neo4jLogger $logger,
) {
}

public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
{
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using OpenIDConnectAuth');

/**
* @psalm-suppress ImpureMethodCall Request is a pure object:
*
Expand Down
12 changes: 3 additions & 9 deletions src/Basic/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@
use Laudis\Neo4j\Databags\SummarizedResult;
use Laudis\Neo4j\Databags\TransactionConfiguration;
use Laudis\Neo4j\Types\CypherList;
use Laudis\Neo4j\Types\CypherMap;

/**
* @implements ClientInterface<SummarizedResult<CypherMap>>
*/
final class Client implements ClientInterface
{
/**
* @param ClientInterface<SummarizedResult<CypherMap>> $client
*/
public function __construct(
private readonly ClientInterface $client
) {}
private readonly ClientInterface $client,
) {
}

public function run(string $statement, iterable $parameters = [], ?string $alias = null): SummarizedResult
{
Expand Down
13 changes: 3 additions & 10 deletions src/Basic/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,19 @@
use Laudis\Neo4j\Contracts\DriverInterface;
use Laudis\Neo4j\Databags\DriverConfiguration;
use Laudis\Neo4j\Databags\SessionConfiguration;
use Laudis\Neo4j\Databags\SummarizedResult;
use Laudis\Neo4j\DriverFactory;
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
use Laudis\Neo4j\Types\CypherMap;
use Psr\Http\Message\UriInterface;

/**
* @implements DriverInterface<SummarizedResult<CypherMap>>
*/
final class Driver implements DriverInterface
{
/**
* @param DriverInterface<SummarizedResult<CypherMap>> $driver
*
* @psalm-external-mutation-free
*/
public function __construct(
private readonly DriverInterface $driver
) {}
private readonly DriverInterface $driver,
) {
}

/**
* @psalm-mutation-free
Expand All @@ -52,7 +46,6 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool

public static function create(string|UriInterface $uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
{
/** @var DriverInterface<SummarizedResult<CypherMap>> */
$driver = DriverFactory::create($uri, $configuration, $authenticate, SummarizedResultFormatter::create());

return new self($driver);
Expand Down
19 changes: 4 additions & 15 deletions src/Basic/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,31 @@
use Laudis\Neo4j\Databags\SummarizedResult;
use Laudis\Neo4j\Databags\TransactionConfiguration;
use Laudis\Neo4j\Types\CypherList;
use Laudis\Neo4j\Types\CypherMap;

/**
* @implements SessionInterface<SummarizedResult<CypherMap>>
*/
final class Session implements SessionInterface
{
/**
* @param SessionInterface<SummarizedResult<CypherMap>> $session
*/
public function __construct(
private readonly SessionInterface $session
) {}
private readonly SessionInterface $session,
) {
}

/**
* @param iterable<Statement> $statements
*
* @return CypherList<SummarizedResult<CypherMap>>
* @return CypherList<SummarizedResult>
*/
public function runStatements(iterable $statements, ?TransactionConfiguration $config = null): CypherList
{
return $this->session->runStatements($statements, $config);
}

/**
* @return SummarizedResult<CypherMap>
*/
public function runStatement(Statement $statement, ?TransactionConfiguration $config = null): SummarizedResult
{
return $this->session->runStatement($statement, $config);
}

/**
* @param iterable<string, mixed> $parameters
*
* @return SummarizedResult<CypherMap>
*/
public function run(string $statement, iterable $parameters = [], ?TransactionConfiguration $config = null): SummarizedResult
{
Expand Down
21 changes: 5 additions & 16 deletions src/Basic/UnmanagedTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,22 @@
use Laudis\Neo4j\Databags\Statement;
use Laudis\Neo4j\Databags\SummarizedResult;
use Laudis\Neo4j\Types\CypherList;
use Laudis\Neo4j\Types\CypherMap;

/**
* @implements UnmanagedTransactionInterface<SummarizedResult<CypherMap>>
*/
final class UnmanagedTransaction implements UnmanagedTransactionInterface
{
/**
* @param UnmanagedTransactionInterface<SummarizedResult<CypherMap>> $tsx
*/
public function __construct(
private readonly UnmanagedTransactionInterface $tsx
) {}
private readonly UnmanagedTransactionInterface $tsx,
) {
}

/**
* @param iterable<string, mixed> $parameters
*
* @return SummarizedResult<CypherMap>
*/
public function run(string $statement, iterable $parameters = []): SummarizedResult
{
return $this->tsx->run($statement, $parameters);
}

/**
* @return SummarizedResult<CypherMap>
*/
public function runStatement(Statement $statement): SummarizedResult
{
return $this->tsx->runStatement($statement);
Expand All @@ -52,7 +41,7 @@ public function runStatement(Statement $statement): SummarizedResult
/**
* @param iterable<Statement> $statements
*
* @return CypherList<SummarizedResult<CypherMap>>
* @return CypherList<SummarizedResult>
*/
public function runStatements(iterable $statements): CypherList
{
Expand All @@ -62,7 +51,7 @@ public function runStatements(iterable $statements): CypherList
/**
* @param iterable<Statement> $statements
*
* @return CypherList<SummarizedResult<CypherMap>>
* @return CypherList<SummarizedResult>
*/
public function commit(iterable $statements = []): CypherList
{
Expand Down
Loading
Loading