Skip to content

Commit 18fad0d

Browse files
committed
Updated Code style
1 parent 149c3cc commit 18fad0d

File tree

11 files changed

+155
-173
lines changed

11 files changed

+155
-173
lines changed

.php_cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ return PhpCsFixer\Config::create()
2323
])
2424
->setFinder(
2525
PhpCsFixer\Finder::create()
26-
->exclude(['vendor'])
26+
->exclude(['vendor', 'build', 'doc'])
2727
->in(__DIR__)
2828
)
2929
;
Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
<?php
22
/**
3-
* File containing the BinaryFile Type class
3+
* File containing the BinaryFile Type class.
44
*
55
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
66
* @license For full copyright and license information view LICENSE file distributed with this source code.
7+
*
78
* @version //autogentag//
89
*/
910

1011
namespace Netgen\Bundle\EnhancedBinaryFileBundle\Core\FieldType\EnhancedBinaryFile;
1112

1213
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
14+
use eZ\Publish\Core\FieldType\BinaryFile\Type as BinaryFileType;
1315
use eZ\Publish\Core\FieldType\ValidationError;
1416
use eZ\Publish\Core\MVC\ConfigResolverInterface;
15-
use eZ\Publish\SPI\IO\MimeTypeDetector;
1617
use eZ\Publish\SPI\FieldType\Value as SPIValue;
17-
use eZ\Publish\Core\FieldType\BinaryFile\Type as BinaryFileType;
18+
use eZ\Publish\SPI\IO\MimeTypeDetector;
1819

1920
class Type extends BinaryFileType
2021
{
21-
2222
/**
23-
* A settings whitelist used in validateFieldSettings method
23+
* A settings whitelist used in validateFieldSettings method.
2424
*
2525
* @var array
2626
*/
2727
protected $settingsSchema = array(
2828
'allowedTypes' => array(
2929
'type' => 'string',
3030
'default' => null,
31-
)
31+
),
3232
);
3333

3434
/**
35-
* @var \eZ\Publish\SPI\IO\MimeTypeDetector $mimeTypeDetector
35+
* @var \eZ\Publish\SPI\IO\MimeTypeDetector
3636
*/
3737
protected $mimeTypeDetector;
3838

@@ -45,7 +45,7 @@ class Type extends BinaryFileType
4545
* @param \eZ\Publish\SPI\IO\MimeTypeDetector $mimeTypeDetector
4646
* @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver
4747
*/
48-
public function __construct( MimeTypeDetector $mimeTypeDetector, ConfigResolverInterface $configResolver )
48+
public function __construct(MimeTypeDetector $mimeTypeDetector, ConfigResolverInterface $configResolver)
4949
{
5050
$this->mimeTypeDetector = $mimeTypeDetector;
5151
$this->configResolver = $configResolver;
@@ -63,78 +63,62 @@ public function getEmptyValue()
6363
}
6464

6565
/**
66-
* Creates a specific value of the derived class from $inputValue
67-
*
68-
* @param array $inputValue
69-
*
70-
* @return Value
71-
*/
72-
protected function createValue( array $inputValue )
73-
{
74-
return new Value( $inputValue );
75-
}
76-
77-
/**
78-
* Returns the field type identifier for this field type
66+
* Returns the field type identifier for this field type.
7967
*
8068
* @return string
8169
*/
8270
public function getFieldTypeIdentifier()
8371
{
84-
return "enhancedezbinaryfile";
72+
return 'enhancedezbinaryfile';
8573
}
8674

87-
8875
/**
89-
* Validates a field based on the validators in the field definition
76+
* Validates a field based on the validators in the field definition.
9077
*
91-
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
9278
*
9379
* @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field
9480
* @param \eZ\Publish\Core\FieldType\BinaryBase\Value $fieldValue The field value for which an action is performed
9581
*
82+
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
83+
*
9684
* @return \eZ\Publish\SPI\FieldType\ValidationError[]
9785
*/
98-
public function validate( FieldDefinition $fieldDefinition, SPIValue $fieldValue )
86+
public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue)
9987
{
10088
$errors = array();
10189

102-
if ( $this->isEmptyValue( $fieldValue ) )
103-
{
90+
if ($this->isEmptyValue($fieldValue)) {
10491
return $errors;
10592
}
10693

10794
$fieldSettings = $fieldDefinition->getFieldSettings();
108-
$allowedExtensions = explode( '|', $fieldSettings['allowedTypes'] );
95+
$allowedExtensions = explode('|', $fieldSettings['allowedTypes']);
10996

110-
$mimeType = $this->mimeTypeDetector->getFromPath( $fieldValue->inputUri );
97+
$mimeType = $this->mimeTypeDetector->getFromPath($fieldValue->inputUri);
11198

112-
foreach ( $allowedExtensions as $allowedExtension )
113-
{
114-
if ( $this->configResolver->hasParameter( "{$allowedExtension}.Types", 'mime' ) )
115-
{
116-
$allowedMimeTypes = $this->configResolver->getParameter( "{$allowedExtension}.Types", 'mime' );
99+
foreach ($allowedExtensions as $allowedExtension) {
100+
if ($this->configResolver->hasParameter("{$allowedExtension}.Types", 'mime')) {
101+
$allowedMimeTypes = $this->configResolver->getParameter("{$allowedExtension}.Types", 'mime');
117102

118-
if ( in_array( $mimeType, $allowedMimeTypes ) )
119-
{
120-
return parent::validate( $fieldDefinition, $fieldValue );
103+
if (in_array($mimeType, $allowedMimeTypes, true)) {
104+
return parent::validate($fieldDefinition, $fieldValue);
121105
}
122106
}
123107
}
124108

125109
return array(
126110
new ValidationError(
127-
"This mimeType is not allowed %mimeType%.",
128-
"These mimeTypes are not allowed %mimeType%.",
111+
'This mimeType is not allowed %mimeType%.',
112+
'These mimeTypes are not allowed %mimeType%.',
129113
array(
130-
"mimeType" => $mimeType,
114+
'mimeType' => $mimeType,
131115
)
132-
)
116+
),
133117
);
134118
}
135119

136120
/**
137-
* Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct
121+
* Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.
138122
*
139123
* This method expects that given $fieldSettings are complete, for this purpose method
140124
* {@link self::applyDefaultSettings()} is provided.
@@ -143,19 +127,18 @@ public function validate( FieldDefinition $fieldDefinition, SPIValue $fieldValue
143127
*
144128
* @return \eZ\Publish\SPI\FieldType\ValidationError[]
145129
*/
146-
public function validateFieldSettings( $fieldSettings )
130+
public function validateFieldSettings($fieldSettings)
147131
{
148132
$validationErrors = array();
149133

150-
if ( !is_array( $fieldSettings ) ) {
151-
$validationErrors[] = new ValidationError( 'Field settings must be in form of an array' );
134+
if (!is_array($fieldSettings)) {
135+
$validationErrors[] = new ValidationError('Field settings must be in form of an array');
152136

153137
return $validationErrors;
154138
}
155139

156-
foreach ( $fieldSettings as $name => $value)
157-
{
158-
switch ( $name ) {
140+
foreach ($fieldSettings as $name => $value) {
141+
switch ($name) {
159142
case 'allowedTypes':
160143
// Nothing to validate, just recognize this setting as known
161144
break;
@@ -173,4 +156,16 @@ public function validateFieldSettings( $fieldSettings )
173156

174157
return $validationErrors;
175158
}
159+
160+
/**
161+
* Creates a specific value of the derived class from $inputValue.
162+
*
163+
* @param array $inputValue
164+
*
165+
* @return Value
166+
*/
167+
protected function createValue(array $inputValue)
168+
{
169+
return new Value($inputValue);
170+
}
176171
}

bundle/Core/FieldType/EnhancedBinaryFile/Value.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace Netgen\Bundle\EnhancedBinaryFileBundle\Core\FieldType\EnhancedBinaryFile;
54

65
use eZ\Publish\Core\FieldType\BinaryFile\Value as BinaryFileValue;

bundle/Core/Persistence/Legacy/Content/FieldValue/Converter/Converter.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,42 @@
33
namespace Netgen\Bundle\EnhancedBinaryFileBundle\Core\Persistence\Legacy\Content\FieldValue\Converter;
44

55
use eZ\Publish\Core\FieldType\FieldSettings;
6+
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter as ConverterInterface;
7+
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
8+
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
69
use eZ\Publish\SPI\Persistence\Content\FieldTypeConstraints;
710
use eZ\Publish\SPI\Persistence\Content\FieldValue;
8-
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
911
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
10-
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
11-
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter as ConverterInterface;
12-
1312

1413
class Converter implements ConverterInterface
1514
{
1615
/**
17-
* Converts data from $value to $storageFieldValue
16+
* Converts data from $value to $storageFieldValue.
1817
*
1918
* @param \eZ\Publish\SPI\Persistence\Content\FieldValue $value
2019
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $storageFieldValue
2120
*/
22-
public function toStorageValue( FieldValue $value, StorageFieldValue $storageFieldValue )
21+
public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
2322
{
2423
}
2524

2625
/**
27-
* Converts data from $value to $fieldValue
26+
* Converts data from $value to $fieldValue.
2827
*
2928
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value
3029
* @param \eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue
3130
*/
32-
public function toFieldValue( StorageFieldValue $value, FieldValue $fieldValue )
31+
public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
3332
{
3433
}
3534

3635
/**
37-
* Converts field definition data in $fieldDef into $storageFieldDef
36+
* Converts field definition data in $fieldDef into $storageFieldDef.
3837
*
3938
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
4039
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
4140
*/
42-
public function toStorageFieldDefinition( FieldDefinition $fieldDef, StorageFieldDefinition $storageDef )
41+
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
4342
{
4443
$storageDef->dataInt1 = isset($fieldDef->fieldTypeConstraints->validators['FileSizeValidator']['maxFileSize']) ?
4544
$fieldDef->fieldTypeConstraints->validators['FileSizeValidator']['maxFileSize'] :
@@ -50,31 +49,31 @@ public function toStorageFieldDefinition( FieldDefinition $fieldDef, StorageFiel
5049
}
5150

5251
/**
53-
* Converts field definition data in $storageDef into $fieldDef
52+
* Converts field definition data in $storageDef into $fieldDef.
5453
*
5554
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
5655
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
5756
*/
58-
public function toFieldDefinition( StorageFieldDefinition $storageDef, FieldDefinition $fieldDef )
57+
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
5958
{
6059
$fieldDef->fieldTypeConstraints = new FieldTypeConstraints(
6160
array(
6261
'validators' => array(
6362
'FileSizeValidator' => array(
64-
'maxFileSize' => ( $storageDef->dataInt1 != 0
63+
'maxFileSize' => (0 !== $storageDef->dataInt1
6564
? $storageDef->dataInt1
66-
: false ),
67-
)
65+
: false),
66+
),
6867
),
69-
'fieldSettings' => new FieldSettings( array(
70-
"allowedTypes" => $storageDef->dataText1
71-
) )
68+
'fieldSettings' => new FieldSettings(array(
69+
'allowedTypes' => $storageDef->dataText1,
70+
)),
7271
)
7372
);
7473
}
7574

7675
/**
77-
* Returns the name of the index column in the attribute table
76+
* Returns the name of the index column in the attribute table.
7877
*
7978
* Returns the name of the index column the datatype uses, which is either
8079
* "sort_key_int" or "sort_key_string". This column is then used for

bundle/DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
class Configuration implements ConfigurationInterface
99
{
1010
/**
11-
* {@inheritDoc}
11+
* {@inheritdoc}
1212
*/
1313
public function getConfigTreeBuilder()
1414
{
1515
$treeBuilder = new TreeBuilder();
16-
$rootNode = $treeBuilder->root( 'netgen_enhanced_ez_binary_file' );
16+
$rootNode = $treeBuilder->root('netgen_enhanced_ez_binary_file');
1717

1818
// Here you should define the parameters that are allowed to
1919
// configure your bundle. See the documentation linked above for

bundle/DependencyInjection/NetgenEnhancedBinaryFileExtension.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22

33
namespace Netgen\Bundle\EnhancedBinaryFileBundle\DependencyInjection;
44

5-
use Symfony\Component\DependencyInjection\ContainerBuilder;
65
use Symfony\Component\Config\FileLocator;
7-
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
87
use Symfony\Component\DependencyInjection\Loader;
8+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
99

1010
class NetgenEnhancedBinaryFileExtension extends Extension
1111
{
1212
/**
13-
* {@inheritDoc}
13+
* {@inheritdoc}
1414
*/
15-
public function load( array $configs, ContainerBuilder $container )
15+
public function load(array $configs, ContainerBuilder $container)
1616
{
1717
$configuration = new Configuration();
18-
$config = $this->processConfiguration( $configuration, $configs );
19-
20-
$loader = new Loader\YamlFileLoader( $container, new FileLocator( __DIR__ . '/../Resources/config' ) );
21-
$loader->load( 'fieldtypes.yml' );
22-
$loader->load( 'field_type_handlers.yml' );
23-
$loader->load( 'storage_engines.yml' );
24-
$loader->load( 'mime.yml' );
18+
$config = $this->processConfiguration($configuration, $configs);
2519

20+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
21+
$loader->load('fieldtypes.yml');
22+
$loader->load('field_type_handlers.yml');
23+
$loader->load('storage_engines.yml');
24+
$loader->load('mime.yml');
2625
}
2726
}

0 commit comments

Comments
 (0)