Skip to content

Commit

Permalink
Use LMBR Coding Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
carusogabriel committed Oct 16, 2018
1 parent 546e910 commit de412eb
Show file tree
Hide file tree
Showing 62 changed files with 114 additions and 171 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/build
/site
composer.lock
.phpcs-cache
1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ before_script:

script:
- mkdir -p build/logs
- vendor/bin/phpcs
- phpunit -c phpunit.xml.dist && make sniff

after_script:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sniff:
vendor/bin/phpcs ./src --standard='./coding_standard.xml' -n
vendor/bin/phpcs

phpunit:
vendor/bin/phpunit
Expand Down
7 changes: 0 additions & 7 deletions coding_standard.xml

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"mockery/mockery": "^1.0",
"satooshi/php-coveralls": "^1.0",
"phpunit/phpunit": "^6.4",
"squizlabs/php_codesniffer": "^2.0",
"sami/sami": "^4.0"
"sami/sami": "^4.0",
"leroy-merlin-br/coding-standard": "^0.1.1"
},
"autoload": {
"psr-4": {
Expand Down
30 changes: 30 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<ruleset name="Mongolid">
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="45"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>

<!-- Ignore warnings and show progress of the run -->
<arg value="nps"/>

<!-- Folders that will be tracked -->
<file>bootstrap</file>
<file>src</file>
<file>tests</file>

<rule ref="LeroyMerlin"/>

<!-- Excluded patterns in some folders -->
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>tests/TestCase.php</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>tests/Mongolid/DataMapper/EntityAssemblerTest.php</exclude-pattern>
</rule>
<!-- Multiple classes confuses this sniff -->
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>tests/Mongolid/DataMapper/EntityAssemblerTest.php</exclude-pattern>
</rule>
</ruleset>
9 changes: 4 additions & 5 deletions src/Mongolid/ActiveRecord.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid;

use BadMethodCallException;
Expand Down Expand Up @@ -165,7 +164,7 @@ public static function first(
* @param array $projection fields to project in Mongo query
* @param bool $useCache retrieves the entity through a CacheableCursor
*
* @throws ModelNotFoundException if no document was found
* @throws ModelNotFoundException If no document was found
*
* @return ActiveRecord
*/
Expand Down Expand Up @@ -208,7 +207,7 @@ public static function firstOrNew($id)
* @param mixed $method name of the method that is being called
* @param mixed $parameters parameters of $method
*
* @throws BadMethodCallException in case of invalid methods be called
* @throws BadMethodCallException In case of invalid methods be called
*
* @return mixed
*/
Expand Down Expand Up @@ -260,7 +259,7 @@ public function getDataMapper()
*/
public function getCollectionName()
{
return $this->collection ? $this->collection : $this->getSchema()->collection;
return $this->collection ?: $this->getSchema()->collection;
}

/**
Expand Down Expand Up @@ -343,7 +342,7 @@ protected function execute(string $action)
/**
* Returns the a valid instance from Ioc.
*
* @throws NoCollectionNameException throws exception when has no collection filled
* @throws NoCollectionNameException Throws exception when has no collection filled
*
* @return mixed
*/
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Connection/Connection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Connection;

use MongoDB\Client;
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Connection/Pool.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Connection;

use Mongolid\Container\Ioc;
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Container/Ioc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Container;

use Illuminate\Contracts\Container\Container as IlluminateContainer;
Expand Down
5 changes: 0 additions & 5 deletions src/Mongolid/Cursor/CacheableCursor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Cursor;

use ArrayIterator;
Expand Down Expand Up @@ -52,8 +51,6 @@ class CacheableCursor extends Cursor
* The difference between the CacheableCursor and the normal Cursor is that
* the Cacheable stores all the results within itself and drops the
* Driver Cursor in order to be serializable.
*
* @return Traversable
*/
protected function getCursor(): Traversable
{
Expand Down Expand Up @@ -141,8 +138,6 @@ protected function getLimit()
/**
* Returns the DriverCursor considering the documents that have already
* been retrieved from cache.
*
* @return Traversable
*/
protected function getOriginalCursor(): Traversable
{
Expand Down
11 changes: 3 additions & 8 deletions src/Mongolid/Cursor/Cursor.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php

namespace Mongolid\Cursor;

use IteratorIterator;
use MongoDB\Driver\ReadPreference;
use Serializable;
use Traversable;
use MongoDB\Collection;
use MongoDB\Driver\Cursor as DriverCursor;
use MongoDB\Driver\Exception\LogicException;
use MongoDB\Driver\ReadPreference;
use Mongolid\ActiveRecord;
use Mongolid\Connection\Pool;
use Mongolid\Container\Ioc;
use Mongolid\DataMapper\EntityAssembler;
use Mongolid\Schema\Schema;
use Serializable;
use Traversable;

/**
* This class wraps the query execution and the actual creation of the driver cursor.
Expand Down Expand Up @@ -262,8 +261,6 @@ public function next()

/**
* Iterator valid method (used in foreach).
*
* @return bool
*/
public function valid(): bool
{
Expand Down Expand Up @@ -302,8 +299,6 @@ public function toArray(): array
* Actually returns a Traversable object with the DriverCursor within.
* If it does not exists yet, create it using the $collection, $command and
* $params given.
*
* @return Traversable
*/
protected function getCursor(): Traversable
{
Expand Down
5 changes: 0 additions & 5 deletions src/Mongolid/Cursor/CursorFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Cursor;

use MongoDB\Collection;
Expand All @@ -18,8 +17,6 @@ class CursorFactory
* @param string $command the command that is being called in the $collection
* @param array $params the parameters of the $command
* @param bool $cacheable retrieves a CacheableCursor instead
*
* @return Cursor
*/
public function createCursor(
Schema $entitySchema,
Expand All @@ -38,8 +35,6 @@ public function createCursor(
*
* @param string $entityClass class of the objects that will be retrieved by the cursor
* @param array $items the items array
*
* @return CursorInterface
*/
public function createEmbeddedCursor(string $entityClass, array $items): CursorInterface
{
Expand Down
3 changes: 1 addition & 2 deletions src/Mongolid/Cursor/CursorInterface.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace Mongolid\Cursor;

use Iterator;
use Countable;
use Iterator;

/**
* Common interface for all kinds of cursors.
Expand Down
3 changes: 0 additions & 3 deletions src/Mongolid/Cursor/EmbeddedCursor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Cursor;

use Mongolid\ActiveRecord;
Expand Down Expand Up @@ -152,8 +151,6 @@ public function current()

/**
* Retrieve a schema based on Entity Class.
*
* @return Schema
*/
protected function getSchemaForEntity(): Schema
{
Expand Down
9 changes: 0 additions & 9 deletions src/Mongolid/DataMapper/BulkWrite.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\DataMapper;

use MongoDB\BSON\ObjectId;
Expand Down Expand Up @@ -37,11 +36,6 @@ class BulkWrite
*/
protected $schema;

/**
* BulkWrite constructor.
*
* @param HasSchemaInterface $entity
*/
public function __construct(HasSchemaInterface $entity)
{
$this->setBulkWrite(new MongoBulkWrite(['ordered' => false]));
Expand All @@ -63,8 +57,6 @@ public function getBulkWrite()
* Set BulkWrite object that will receive all operations
* and later be executed.
*
* @param MongoBulkWrite $bulkWrite
*
* @return $this
*/
public function setBulkWrite(MongoBulkWrite $bulkWrite)
Expand All @@ -84,7 +76,6 @@ public function setBulkWrite(MongoBulkWrite $bulkWrite)
* @param ObjectId|string $id
* @param array $dataToSet
* @param array $options
* @param string $operator
*/
public function updateOne(
$id,
Expand Down
15 changes: 3 additions & 12 deletions src/Mongolid/DataMapper/DataMapper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\DataMapper;

use InvalidArgumentException;
Expand Down Expand Up @@ -234,8 +233,6 @@ public function delete($entity, array $options = []): bool
* @param mixed $query mongoDB query to retrieve documents
* @param array $projection fields to project in Mongo query
* @param bool $cacheable retrieves a CacheableCursor instead
*
* @return \Mongolid\Cursor\Cursor
*/
public function where(
$query = [],
Expand All @@ -260,8 +257,6 @@ public function where(
/**
* Retrieve a database cursor that will return all documents as
* $this->schema->entityClass objects upon iteration.
*
* @return \Mongolid\Cursor\Cursor
*/
public function all(): Cursor
{
Expand Down Expand Up @@ -309,7 +304,7 @@ public function first(
* @param array $projection fields to project in Mongo query
* @param bool $cacheable retrieves the first through a CacheableCursor
*
* @throws ModelNotFoundException if no document was found
* @throws ModelNotFoundException If no document was found
*
* @return mixed First document matching query as an $this->schema->entityClass object
*/
Expand Down Expand Up @@ -362,8 +357,6 @@ protected function getSchemaMapper()

/**
* Retrieves the Collection object.
*
* @return Collection
*/
protected function getCollection(): Collection
{
Expand Down Expand Up @@ -457,7 +450,7 @@ protected function fireEvent(string $event, $entity, bool $halt = false)
{
$event = "mongolid.{$event}: ".get_class($entity);

$this->eventService ? $this->eventService : $this->eventService = Ioc::make(EventTriggerService::class);
$this->eventService ?: $this->eventService = Ioc::make(EventTriggerService::class);

return $this->eventService->fire($event, $entity, $halt);
}
Expand All @@ -481,7 +474,7 @@ protected function fireEvent(string $event, $entity, bool $halt = false)
*
* @param array $fields fields to project
*
* @throws InvalidArgumentException if the given $fields are not a valid projection
* @throws InvalidArgumentException If the given $fields are not a valid projection
*
* @return array
*/
Expand Down Expand Up @@ -563,8 +556,6 @@ public function getSchema(): Schema

/**
* Set a Schema object that describes an Entity in MongoDB.
*
* @param Schema $schema
*/
public function setSchema(Schema $schema)
{
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/DataMapper/EntityAssembler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\DataMapper;

use Mongolid\Container\Ioc;
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/DataMapper/SchemaMapper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\DataMapper;

use Mongolid\Container\Ioc;
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Event/EventTriggerInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Event;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Event/EventTriggerService.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Event;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Exception/ModelNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Exception;

use RuntimeException;
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Exception/NoCollectionNameException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Exception;

use Exception;
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Manager.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid;

use Illuminate\Container\Container;
Expand Down
1 change: 0 additions & 1 deletion src/Mongolid/Model/Attributes.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Mongolid\Model;

/**
Expand Down
Loading

0 comments on commit de412eb

Please sign in to comment.