From 5c605b6f4f4c30cedf7c228ca1c6909cb19a0b92 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 23 Apr 2021 10:45:45 +0200 Subject: [PATCH 1/2] Add final for every method of abstract classes --- src/Builder/AbstractFormContractor.php | 11 +++ src/Datagrid/Pager.php | 40 ++++++++ src/FieldDescription/BaseFieldDescription.php | 97 +++++++++++++++++++ src/Filter/Filter.php | 64 +++++++++++- src/Mapper/BaseGroupedMapper.php | 22 +++++ src/Templating/AbstractTemplateRegistry.php | 8 ++ src/Util/ObjectAclManipulator.php | 2 + 7 files changed, 242 insertions(+), 2 deletions(-) diff --git a/src/Builder/AbstractFormContractor.php b/src/Builder/AbstractFormContractor.php index bf8319e3cb..26e45238b7 100644 --- a/src/Builder/AbstractFormContractor.php +++ b/src/Builder/AbstractFormContractor.php @@ -38,6 +38,9 @@ public function __construct(FormFactoryInterface $formFactory) $this->formFactory = $formFactory; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) { $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'standard')); @@ -49,6 +52,8 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter } /** + * @final since sonata-project/admin-bundle 3.x. + * * @return FormFactoryInterface */ public function getFormFactory() @@ -56,11 +61,17 @@ public function getFormFactory() return $this->formFactory; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFormBuilder($name, array $formOptions = []) { return $this->getFormFactory()->createNamedBuilder($name, FormType::class, null, $formOptions); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) { // NEXT_MAJOR: Remove this line and update the function signature. diff --git a/src/Datagrid/Pager.php b/src/Datagrid/Pager.php index 6c38550ecb..6055d152f8 100644 --- a/src/Datagrid/Pager.php +++ b/src/Datagrid/Pager.php @@ -196,6 +196,8 @@ public function setMaxRecordLimit($limit) } /** + * @final since sonata-project/admin-bundle 3.x. + * * Returns an array of page numbers to use in pagination links. * * @param int $nbLinks The maximum number of page numbers to return @@ -225,6 +227,8 @@ public function getLinks($nbLinks = null) } /** + * @final since sonata-project/admin-bundle 3.x. + * * Returns true if the current query requires pagination. * * @return bool @@ -479,6 +483,8 @@ public function getNbResults() } /** + * @final since sonata-project/admin-bundle 3.x. + * * @return int */ public function getFirstPage() @@ -487,6 +493,8 @@ public function getFirstPage() } /** + * @final since sonata-project/admin-bundle 3.x. + * * @return int */ public function getLastPage() @@ -495,6 +503,8 @@ public function getLastPage() } /** + * @final since sonata-project/admin-bundle 3.x. + * * @return int */ public function getPage() @@ -503,6 +513,8 @@ public function getPage() } /** + * @final since sonata-project/admin-bundle 3.x. + * * @return int */ public function getNextPage() @@ -511,6 +523,8 @@ public function getNextPage() } /** + * @final since sonata-project/admin-bundle 3.x. + * * @return int */ public function getPreviousPage() @@ -518,6 +532,9 @@ public function getPreviousPage() return max($this->getPage() - 1, $this->getFirstPage()); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setPage($page) { $this->page = (int) $page; @@ -528,11 +545,17 @@ public function setPage($page) } } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getMaxPerPage() { return $this->maxPerPage; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setMaxPerPage($max) { if ($max > 0) { @@ -553,17 +576,25 @@ public function setMaxPerPage($max) } } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getMaxPageLinks() { return $this->maxPageLinks; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setMaxPageLinks($maxPageLinks) { $this->maxPageLinks = $maxPageLinks; } /** + * @final since sonata-project/admin-bundle 3.x. + * * Returns true if on the first page. * * @return bool @@ -574,6 +605,8 @@ public function isFirstPage() } /** + * @final since sonata-project/admin-bundle 3.x. + * * Returns true if on the last page. * * @return bool @@ -854,12 +887,17 @@ public function setCountColumn(array $countColumn) return $this->countColumn = $countColumn; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setQuery($query) { $this->query = $query; } /** + * @final since sonata-project/admin-bundle 3.x. + * * @return ProxyQueryInterface|null * * @phpstan-return T|null $query @@ -889,6 +927,8 @@ protected function setNbResults($nb) } /** + * @final since sonata-project/admin-bundle 3.x. + * * @param int $page * * @return void diff --git a/src/FieldDescription/BaseFieldDescription.php b/src/FieldDescription/BaseFieldDescription.php index 78ca9999ef..948dd15c68 100644 --- a/src/FieldDescription/BaseFieldDescription.php +++ b/src/FieldDescription/BaseFieldDescription.php @@ -212,11 +212,17 @@ public function setFieldName($fieldName) $this->fieldName = $fieldName; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFieldName() { return $this->fieldName; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setName($name) { $this->name = $name; @@ -227,21 +233,33 @@ public function setName($name) } } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getName() { return $this->name; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getOption($name, $default = null) { return $this->options[$name] ?? $default; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setOption($name, $value) { $this->options[$name] = $value; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setOptions(array $options) { // set the type if provided @@ -282,16 +300,25 @@ public function setOptions(array $options) $this->options = $options; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getOptions() { return $this->options; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setTemplate($template) { $this->template = $template; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getTemplate() { if (null !== $this->template && !\is_string($this->template) && 'sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { @@ -305,21 +332,33 @@ public function getTemplate() return $this->template; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setType($type) { $this->type = $type; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getType() { return $this->type; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setParent(AdminInterface $parent) { $this->parent = $parent; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getParent() { if (!$this->hasParent()) { @@ -339,32 +378,50 @@ public function getParent() return $this->parent; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function hasParent() { return null !== $this->parent; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getAssociationMapping() { return $this->associationMapping; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFieldMapping() { return $this->fieldMapping; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getParentAssociationMappings() { return $this->parentAssociationMappings; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setAssociationAdmin(AdminInterface $associationAdmin) { $this->associationAdmin = $associationAdmin; $this->associationAdmin->setParentFieldDescription($this); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getAssociationAdmin() { if (!$this->hasAssociationAdmin()) { @@ -385,6 +442,9 @@ public function getAssociationAdmin() return $this->associationAdmin; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function hasAssociationAdmin() { return null !== $this->associationAdmin; @@ -393,6 +453,8 @@ public function hasAssociationAdmin() /** * NEXT_MAJOR: Change the visibility to protected. * + * @final since sonata-project/admin-bundle 3.x. + * * @param object|null $object * @param string $fieldName * @@ -527,11 +589,17 @@ public function getFieldValue($object, $fieldName) )); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setAdmin(AdminInterface $admin) { $this->admin = $admin; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getAdmin() { if (!$this->hasAdmin()) { @@ -551,11 +619,17 @@ public function getAdmin() return $this->admin; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function hasAdmin() { return null !== $this->admin; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function mergeOption($name, array $options = []) { if (!isset($this->options[$name])) { @@ -569,6 +643,9 @@ public function mergeOption($name, array $options = []) $this->options[$name] = array_merge($this->options[$name], $options); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function mergeOptions(array $options = []) { $this->setOptions(array_merge_recursive($this->options, $options)); @@ -589,6 +666,9 @@ public function setMappingType($mappingType) $this->mappingType = $mappingType; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getMappingType() { return $this->mappingType; @@ -660,6 +740,9 @@ public function getHelp() return $this->help; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getLabel() { $label = $this->getOption('label'); @@ -674,21 +757,33 @@ public function getLabel() return $label; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function isSortable() { return false !== $this->getOption('sortable', false); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getSortFieldMapping() { return $this->getOption('sort_field_mapping'); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getSortParentAssociationMapping() { return $this->getOption('sort_parent_association_mappings'); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getTranslationDomain() { return $this->getOption('translation_domain') ?: $this->getAdmin()->getTranslationDomain(); @@ -697,6 +792,8 @@ public function getTranslationDomain() /** * Return true if field is virtual. * + * @final since sonata-project/admin-bundle 3.x. + * * @return bool */ public function isVirtual() diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 23872f693f..b3215c56ee 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -49,17 +49,26 @@ abstract class Filter implements FilterInterface */ private $active = false; + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function initialize($name, array $options = []) { $this->name = $name; $this->setOptions($options); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getName() { return $this->name; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFormName() { /* @@ -72,6 +81,9 @@ public function getFormName() return str_replace('.', '__', $this->name); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getOption($name, $default = null) { if (\array_key_exists($name, $this->options)) { @@ -81,21 +93,33 @@ public function getOption($name, $default = null) return $default; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setOption($name, $value) { $this->options[$name] = $value; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFieldType() { return $this->getOption('field_type', TextType::class); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFieldOptions() { return $this->getOption('field_options', ['required' => false]); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFieldOption($name, $default = null) { if (isset($this->options['field_options'][$name]) && \is_array($this->options['field_options'])) { @@ -105,21 +129,33 @@ public function getFieldOption($name, $default = null) return $default; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setFieldOption($name, $value) { $this->options['field_options'][$name] = $value; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getLabel() { return $this->getOption('label'); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setLabel($label) { $this->setOption('label', $label); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFieldName() { $fieldName = $this->getOption('field_name'); @@ -134,11 +170,17 @@ public function getFieldName() return $fieldName; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getParentAssociationMappings() { return $this->getOption('parent_association_mappings', []); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getFieldMapping() { $fieldMapping = $this->getOption('field_mapping'); @@ -153,6 +195,9 @@ public function getFieldMapping() return $fieldMapping; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getAssociationMapping() { $associationMapping = $this->getOption('association_mapping'); @@ -168,7 +213,7 @@ public function getAssociationMapping() } /** - * Set options. + * @final since sonata-project/admin-bundle 3.x. */ public function setOptions(array $options) { @@ -180,7 +225,7 @@ public function setOptions(array $options) } /** - * Get options. + * @final since sonata-project/admin-bundle 3.x. * * @return array */ @@ -223,6 +268,9 @@ public function getValue() return $this->value; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function isActive() { $values = $this->value; @@ -232,21 +280,33 @@ public function isActive() || isset($values['value']) && false !== $values['value'] && '' !== $values['value']; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function setCondition($condition) { $this->condition = $condition; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getCondition() { return $this->condition; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getTranslationDomain() { return $this->getOption('translation_domain'); } + /** + * @final since sonata-project/admin-bundle 3.x. + */ protected function setActive(bool $active): void { $this->active = $active; diff --git a/src/Mapper/BaseGroupedMapper.php b/src/Mapper/BaseGroupedMapper.php index def81d335e..3a3311eebb 100644 --- a/src/Mapper/BaseGroupedMapper.php +++ b/src/Mapper/BaseGroupedMapper.php @@ -40,6 +40,8 @@ abstract class BaseGroupedMapper extends BaseMapper implements MapperInterface protected $apply = []; /** + * @final since sonata-project/admin-bundle 3.x. + * * Add new group or tab (if parameter "tab=true" is available in options). * * @param string $name @@ -175,6 +177,8 @@ public function with($name, array $options = []) } /** + * @final since sonata-project/admin-bundle 3.x. + * * Only nested add if the condition match true. * * @param bool $bool @@ -189,6 +193,8 @@ public function ifTrue($bool) } /** + * @final since sonata-project/admin-bundle 3.x. + * * Only nested add if the condition match false. * * @param bool $bool @@ -203,6 +209,8 @@ public function ifFalse($bool) } /** + * @final since sonata-project/admin-bundle 3.x. + * * @throws \LogicException * * @return static @@ -219,6 +227,8 @@ public function ifEnd() } /** + * @final since sonata-project/admin-bundle 3.x. + * * Add new tab. * * @param string $name @@ -232,6 +242,8 @@ public function tab($name, array $options = []) } /** + * @final since sonata-project/admin-bundle 3.x. + * * Close the current group or tab. * * @throws \LogicException @@ -256,6 +268,8 @@ public function end() } /** + * @final since sonata-project/admin-bundle 3.x. + * * Returns a boolean indicating if there is an open tab at the moment. * * @return bool @@ -266,6 +280,8 @@ public function hasOpenTab() } /** + * @final since sonata-project/admin-bundle 3.x. + * * Removes a group. * * @param string $group The group to delete @@ -307,6 +323,8 @@ public function removeGroup($group, $tab = 'default', $deleteEmptyTab = false) } /** + * @final since sonata-project/admin-bundle 3.x. + * * Removes a tab. * * @return static @@ -370,6 +388,8 @@ protected function getName() } /** + * @final since sonata-project/admin-bundle 3.x. + * * Add the field name to the current group. * * @param string $fieldName @@ -389,6 +409,8 @@ protected function addFieldToCurrentGroup($fieldName) } /** + * @final since sonata-project/admin-bundle 3.x. + * * Return the name of the currently selected group. The method also makes * sure a valid group name is currently selected. * diff --git a/src/Templating/AbstractTemplateRegistry.php b/src/Templating/AbstractTemplateRegistry.php index eb767216a7..79bb39e8de 100644 --- a/src/Templating/AbstractTemplateRegistry.php +++ b/src/Templating/AbstractTemplateRegistry.php @@ -28,17 +28,25 @@ public function __construct(array $templates = []) $this->templates = $templates; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function getTemplates(): array { return $this->templates; } + /** + * @final since sonata-project/admin-bundle 3.x. + */ public function hasTemplate(string $name): bool { return isset($this->templates[$name]); } /** + * @final since sonata-project/admin-bundle 3.x. + * * NEXT_MAJOR: add type hint. * * @param string $name diff --git a/src/Util/ObjectAclManipulator.php b/src/Util/ObjectAclManipulator.php index 9f5ac39d2d..0286514f16 100644 --- a/src/Util/ObjectAclManipulator.php +++ b/src/Util/ObjectAclManipulator.php @@ -24,6 +24,8 @@ abstract class ObjectAclManipulator implements ObjectAclManipulatorInterface { /** + * @final since sonata-project/admin-bundle 3.x. + * * Configure the object ACL for the passed object identities. * * @param AdminInterface $admin From 1979e08731ebc73921c89c65ca72aacdcfdb7823 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 24 Apr 2021 22:47:31 +0200 Subject: [PATCH 2/2] Remove SimplePager::haveToPaginate implementation --- src/Datagrid/SimplePager.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Datagrid/SimplePager.php b/src/Datagrid/SimplePager.php index 00b5f94804..65cccbf60c 100644 --- a/src/Datagrid/SimplePager.php +++ b/src/Datagrid/SimplePager.php @@ -32,6 +32,10 @@ class SimplePager extends Pager protected $results; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * @var bool */ protected $haveToPaginate; @@ -146,11 +150,6 @@ public function getResults($hydrationMode = null) return $this->results; } - public function haveToPaginate() - { - return $this->haveToPaginate || $this->getPage() > 1; - } - /** * {@inheritdoc} *