Skip to content

Commit

Permalink
Merge pull request #841 from doctrine/static-ci
Browse files Browse the repository at this point in the history
cs fixer and phpstan basic level
  • Loading branch information
dbu committed Apr 21, 2023
2 parents 822f290 + 5b9943c commit f7a426c
Show file tree
Hide file tree
Showing 108 changed files with 495 additions and 707 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.yml]
indent_size = 2
47 changes: 47 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Static analysis

on:
push:
branches:
- '[0-9]+.x'
- '[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.x'
pull_request:

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: "curl,dom,json,xml,dom"
coverage: none

- name: Checkout code
uses: actions/checkout@v3

# have to install phpstan ourselves here, the phpstan-ga fails at composer install with weird errors
- name: Install phpstan
run: |
composer require --no-update jackalope/jackalope-doctrine-dbal jackalope/jackalope-jackrabbit phpstan/phpstan
composer update
- name: PHPStan
run: vendor/bin/phpstan analyze --no-progress

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --dry-run --diff
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tests/phpunit.xml
phpunit.xml
.phpunit.result.cache
.php-cs-fixer.cache
/cli-config.php
jackrabbit/
vendor/
Expand Down
18 changes: 18 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/lib')
->in(__DIR__.'/tests')
->name('*.php')
;

$config = new PhpCsFixer\Config();

return $config
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'single_line_throw' => false,
])
->setFinder($finder)
;
19 changes: 5 additions & 14 deletions lib/Doctrine/ODM/PHPCR/ChildrenCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public static function createFromCollection(DocumentManagerInterface $dm, $docum
}

/**
* @param $fetchDepth
*
* @return NodeInterface
*/
private function getNode($fetchDepth)
Expand All @@ -77,8 +75,6 @@ private function getNode($fetchDepth)
}

/**
* @param $childNodes
*
* @return NodeInterface[]
*/
private function getChildren($childNodes)
Expand All @@ -99,7 +95,7 @@ private function getChildren($childNodes)
* Initializes the collection by loading its contents from the database
* if the collection is not yet initialized.
*/
public function initialize()
public function initialize(): void
{
if (!$this->isInitialized()) {
$this->getOriginalNodeNames();
Expand All @@ -110,8 +106,7 @@ public function initialize()
}
}

/** {@inheritdoc} */
public function contains($element)
public function contains($element): bool
{
if (!$this->isInitialized()) {
$uow = $this->dm->getUnitOfWork();
Expand Down Expand Up @@ -141,8 +136,7 @@ public function contains($element)
return parent::contains($element);
}

/** {@inheritdoc} */
public function containsKey($key)
public function containsKey($key): bool
{
if (!$this->isInitialized()) {
return in_array($key, $this->getOriginalNodeNames(), true);
Expand All @@ -151,8 +145,7 @@ public function containsKey($key)
return parent::containsKey($key);
}

/** {@inheritdoc} */
public function count()
public function count(): int
{
if (!$this->isInitialized()) {
return count($this->getOriginalNodeNames());
Expand All @@ -161,8 +154,7 @@ public function count()
return parent::count();
}

/** {@inheritdoc} */
public function isEmpty()
public function isEmpty(): bool
{
if (!$this->isInitialized()) {
return !$this->count();
Expand All @@ -171,7 +163,6 @@ public function isEmpty()
return parent::isEmpty();
}

/** {@inheritdoc} */
public function slice($offset, $length = null)
{
if (!$this->isInitialized()) {
Expand Down
11 changes: 2 additions & 9 deletions lib/Doctrine/ODM/PHPCR/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@
use Psr\Cache\CacheItemPoolInterface;

/**
* Configuration class.
*
* @license http://www.opensource.org/licenses/MIT-license.php MIT license
*
* @link www.doctrine-project.com
* @since 1.0
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Pascal Helfenstein <nicam@nicam.ch>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Pascal Helfenstein <nicam@nicam.ch>
*/
class Configuration
{
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ abstract class DocumentManagerDecorator extends ObjectManagerDecorator implement
*/
protected $wrapped;

/**
* @param DocumentManagerInterface $wrapped
*/
public function __construct(DocumentManagerInterface $wrapped)
{
$this->wrapped = $wrapped;
Expand Down
7 changes: 3 additions & 4 deletions lib/Doctrine/ODM/PHPCR/Document/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class File extends AbstractFile
{
/**
* @var resource
*
* @PHPCRODM\Child(nodeName="jcr:content", cascade="all")
*/
protected $content;
Expand All @@ -26,9 +27,9 @@ class File extends AbstractFile
*
* @param string $filename name of the file which contents should be used
*
* @throws RuntimeException if the filename does not point to a file that can be read
*
* @return $this
*
* @throws RuntimeException if the filename does not point to a file that can be read
*/
public function setFileContentFromFilesystem($filename)
{
Expand Down Expand Up @@ -57,8 +58,6 @@ public function setFileContentFromFilesystem($filename)
/**
* Set the content for this file from the given Resource.
*
* @param resource $content
*
* @return $this
*/
public function setContent(Resource $content)
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ODM/PHPCR/Document/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class Folder extends AbstractFile
{
/**
* @var ArrayCollection
*
* @PHPCRODM\Children(cascade="all")
*/
protected $children;

/**
* @var AbstractFile
*
* @PHPCRODM\Child(cascade="all")
*/
protected $child;
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/ODM/PHPCR/Document/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ class Generic

/**
* @var Collection
*
* @PHPCRODM\Children
*/
protected $children;

/**
* @var Collection
*
* @PHPCRODM\MixedReferrers
*/
protected $referrers;
Expand Down Expand Up @@ -139,8 +141,6 @@ public function setChildren(ArrayCollection $children)
/**
* Add a child to this document.
*
* @param $child
*
* @return $this
*/
public function addChild($child)
Expand Down Expand Up @@ -184,8 +184,6 @@ public function setReferrers(ArrayCollection $referrers)
/**
* Add a referrer to this document.
*
* @param $referrer
*
* @return $this;
*/
public function addReferrer($referrer)
Expand Down
23 changes: 9 additions & 14 deletions lib/Doctrine/ODM/PHPCR/DocumentClassMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,32 @@ interface DocumentClassMapperInterface
/**
* Determine the class name from a given node.
*
* @param DocumentManagerInterface $dm
* @param NodeInterface $node
* @param string $className explicit class to use. If set, this
* class or a subclass of it has to be used. If this is not possible,
* an InvalidArgumentException has to be thrown.
*
* @throws ClassMismatchException if $node represents a class that is not
* a descendant of $className
* @param string $className explicit class to use. If set, this
* class or a subclass of it has to be used. If this is not possible,
* an InvalidArgumentException has to be thrown.
*
* @return string $className if not null, the class configured for this
* node if defined and the Generic document if no better class can be
* found
*
* @throws ClassMismatchException if $node represents a class that is not
* a descendant of $className
*/
public function getClassName(DocumentManagerInterface $dm, NodeInterface $node, $className = null);

/**
* Write any relevant meta data into the node to be able to map back to a class name later.
*
* @param DocumentManagerInterface $dm
* @param NodeInterface $node
* @param string $className
* @param string $className
*/
public function writeMetadata(DocumentManagerInterface $dm, NodeInterface $node, $className);

/**
* Check if the document is instance of the specified $className and
* throw exception if not.
*
* @param DocumentManagerInterface $dm
* @param object $document
* @param string $className
* @param object $document
* @param string $className
*
* @throws ClassMismatchException if document is not of type $className
*/
Expand Down
17 changes: 8 additions & 9 deletions lib/Doctrine/ODM/PHPCR/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ public function getPhpcrSession()
/**
* Factory method for a Document Manager.
*
* @param SessionInterface $session
* @param Configuration $config
* @param EventManager $evm
* @param Configuration $config
* @param EventManager $evm
*
* @return DocumentManager
*/
Expand Down Expand Up @@ -262,7 +261,7 @@ public function getClassMetadata($className)
* If the document is translatable, then the language chooser strategy is
* used to load the best suited language for the translatable fields.
*
* @param null|string $className optional object class name to use
* @param string|null $className optional object class name to use
* @param string $id the path or uuid of the document to find
*
* @return object|null the document if found, otherwise null
Expand Down Expand Up @@ -636,10 +635,10 @@ public function remove($document)
* @param object $document the document to merge over a persisted document
* with the same id
*
* @throws InvalidArgumentException if $document is not an object
*
* @return object The managed document where $document has been merged
* into. This is *not* the same instance as the parameter.
*
* @throws InvalidArgumentException if $document is not an object
*/
public function merge($document)
{
Expand Down Expand Up @@ -841,9 +840,9 @@ public function findVersionByName($className, $id, $versionName)
*
* @param object $document
*
* @throws InvalidArgumentException if $document is not an object
*
* @return bool true if the repository contains the object, false otherwise
*
* @throws InvalidArgumentException if $document is not an object
*/
public function contains($document)
{
Expand Down Expand Up @@ -875,7 +874,7 @@ public function clear($className = null)
if (null === $className) {
$this->unitOfWork->clear();
} else {
//TODO
// TODO
throw new PHPCRException('DocumentManager#clear($className) not yet implemented.');
}
}
Expand Down

0 comments on commit f7a426c

Please sign in to comment.