Skip to content

Commit 9d5bf5d

Browse files
committed
Init
0 parents  commit 9d5bf5d

27 files changed

+1143
-0
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.gitattributes

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.editorconfig export-ignore
2+
.gitattributes export-ignore
3+
/.github/ export-ignore
4+
.gitignore export-ignore
5+
/.php_cs export-ignore
6+
/.scrutinizer.yml export-ignore
7+
/.styleci.yml export-ignore
8+
/.travis.yml export-ignore
9+
/behat.yml.dist export-ignore
10+
/features/ export-ignore
11+
/phpspec.ci.yml export-ignore
12+
/phpspec.yml.dist export-ignore
13+
/phpunit.xml.dist export-ignore
14+
/spec/ export-ignore
15+
/Tests/ export-ignore

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/behat.yml
2+
/build/
3+
/composer.lock
4+
/phpspec.yml
5+
/phpunit.xml
6+
/vendor/

.php_cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/*
4+
* In order to make it work, fabpot/php-cs-fixer and sllh/php-cs-fixer-styleci-bridge must be installed globally
5+
* with composer.
6+
*
7+
* @link https://github.com/Soullivaneuh/php-cs-fixer-styleci-bridge
8+
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer
9+
*/
10+
11+
use SLLH\StyleCIBridge\ConfigBridge;
12+
13+
return ConfigBridge::create();

.scrutinizer.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
filter:
2+
excluded_paths: [vendor/*, Tests/*]
3+
checks:
4+
php:
5+
code_rating: true
6+
duplication: true
7+
tools:
8+
external_code_coverage: true

.styleci.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
preset: symfony
2+
3+
finder:
4+
exclude:
5+
- "Resources"
6+
- "vendor"
7+
8+
enabled:
9+
- short_array_syntax
10+
11+
disabled:
12+
- phpdoc_annotation_without_dot # This is still buggy: https://github.com/symfony/symfony/pull/19198

.travis.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
language: php
2+
3+
sudo: false
4+
5+
cache:
6+
directories:
7+
- $HOME/.composer/cache/files
8+
9+
php:
10+
- 7.0
11+
- 7.1
12+
13+
env:
14+
global:
15+
- TEST_COMMAND="composer test"
16+
matrix:
17+
- SYMFONY_VERSION=3.1.*
18+
- SYMFONY_VERSION=3.0.*
19+
20+
branches:
21+
except:
22+
- /^analysis-.*$/
23+
24+
matrix:
25+
fast_finish: true
26+
include:
27+
- php: 5.5
28+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" SYMFONY_VERSION=3.0.*
29+
30+
install:
31+
- composer require symfony/symfony:${SYMFONY_VERSION} --no-update
32+
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
33+
34+
script:
35+
- $TEST_COMMAND
36+
37+
after_success:
38+
- if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
39+
- if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi

Collector/DebugLogger.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4jBundle\Collector;
4+
5+
use GraphAware\Common\Cypher\Statement;
6+
use GraphAware\Common\Cypher\StatementInterface;
7+
use GraphAware\Common\Result\Result;
8+
use GraphAware\Neo4j\Client\Exception\Neo4jExceptionInterface;
9+
10+
/**
11+
* @author Tobias Nyholm <[email protected]>
12+
*/
13+
final class DebugLogger
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $statement = [];
19+
20+
/**
21+
* @var array
22+
*/
23+
private $result = [];
24+
25+
/**
26+
* @var array
27+
*/
28+
private $exception = [];
29+
30+
/**
31+
* @var int
32+
*/
33+
private $currentStatementId = 0;
34+
35+
/**
36+
* @param StatementInterface $statement
37+
*/
38+
public function addStatement(StatementInterface $statement)
39+
{
40+
$this->statement[++$this->currentStatementId] = $statement;
41+
}
42+
43+
/**
44+
* @param Result $result
45+
*/
46+
public function addResult(Result $result)
47+
{
48+
$this->result[$this->currentStatementId] = $result;
49+
}
50+
51+
/**
52+
* @param Neo4jExceptionInterface $exception
53+
*/
54+
public function addException(Neo4jExceptionInterface $exception)
55+
{
56+
$this->exception[$this->currentStatementId] = $exception;
57+
}
58+
59+
/**
60+
* @return StatementInterface[]
61+
*/
62+
public function getStatements(): array
63+
{
64+
return $this->statement;
65+
}
66+
67+
/**
68+
* @return Result[]
69+
*/
70+
public function getResults(): array
71+
{
72+
return $this->result;
73+
}
74+
75+
/**
76+
* @return Neo4jExceptionInterface[]
77+
*/
78+
public function getExceptions(): array
79+
{
80+
return $this->exception;
81+
}
82+
}

Collector/Neo4jDataCollector.php

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4jBundle\Collector;
4+
5+
use Symfony\Component\HttpFoundation\Request;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
8+
9+
/**
10+
* A data collector for the debug plugin.
11+
*
12+
* @author Tobias Nyholm <[email protected]>
13+
*/
14+
final class Neo4jDataCollector extends DataCollector
15+
{
16+
private $logger;
17+
18+
public function __construct(DebugLogger $logger)
19+
{
20+
$this->logger = $logger;
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function collect(Request $request, Response $response, \Exception $exception = null)
27+
{
28+
}
29+
30+
/**
31+
* @return array|\GraphAware\Common\Cypher\StatementInterface[]
32+
*/
33+
public function getStatements()
34+
{
35+
return $this->logger->getStatements();
36+
}
37+
38+
/**
39+
* @return array|\GraphAware\Common\Result\Result[]
40+
*/
41+
public function getResults()
42+
{
43+
return $this->logger->getResults();
44+
}
45+
46+
/**
47+
* @return array|\GraphAware\Neo4j\Client\Exception\Neo4jExceptionInterface[]
48+
*/
49+
public function getExceptions()
50+
{
51+
return $this->logger->getExceptions();
52+
}
53+
54+
/**
55+
* @param int $idx
56+
*
57+
* @return bool
58+
*/
59+
public function wasSuccessful(int $idx):bool
60+
{
61+
return isset($this->logger->getResults()[$idx]);
62+
}
63+
64+
/**
65+
* @return string
66+
*/
67+
public function getName()
68+
{
69+
return 'neo4j';
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*/
75+
public function serialize()
76+
{
77+
return serialize($this->logger);
78+
}
79+
80+
/**
81+
* {@inheritdoc}
82+
*/
83+
public function unserialize($data)
84+
{
85+
$this->logger = unserialize($data);
86+
}
87+
}
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4jBundle\Collector\Twig;
4+
5+
use GraphAware\Neo4j\Client\Formatter\Type\Node;
6+
7+
/**
8+
* @author Tobias Nyholm <[email protected]>
9+
*/
10+
class Neo4jResultExtension extends \Twig_Extension
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*
15+
* @return array
16+
*/
17+
public function getFilters()
18+
{
19+
return [
20+
new \Twig_SimpleFilter('neo4jResult', [$this, 'getType']),
21+
];
22+
}
23+
24+
/**
25+
* @param string $message http message
26+
*/
27+
public function getType($object)
28+
{
29+
return $this->doGetType($object, true);
30+
31+
}
32+
33+
public function getName()
34+
{
35+
return 'neo4j.result';
36+
}
37+
38+
/**
39+
* @param $object
40+
* @param $recursive
41+
*
42+
* @return string
43+
*/
44+
private function doGetType($object, $recursive):string
45+
{
46+
if ($object instanceof Node) {
47+
return sprintf('%s: %s', $object->identity(), implode(', ', $object->labels()));
48+
} elseif (is_array($object) && $recursive) {
49+
if (empty($object)) {
50+
return 'Empty array';
51+
}
52+
$ret = [];
53+
foreach ($object as $o) {
54+
$ret[] = $this->doGetType($o, false);
55+
}
56+
57+
return sprintf('[%s]', implode(',', $ret));
58+
}
59+
60+
return is_object($object) ? get_class($object) : gettype($object);
61+
}
62+
}

0 commit comments

Comments
 (0)