├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── UPGRADE-v3.md ├── ci-integration.sh ├── composer.json ├── feature-or-bug.rst ├── logo.md ├── logo.png ├── php-cs-fixer └── src ├── AbstractDoctrineAnnotationFixer.php ├── AbstractFixer.php ├── AbstractFopenFlagFixer.php ├── AbstractFunctionReferenceFixer.php ├── AbstractNoUselessElseFixer.php ├── AbstractPhpdocToTypeDeclarationFixer.php ├── AbstractPhpdocTypesFixer.php ├── AbstractProxyFixer.php ├── Cache ├── Cache.php ├── CacheInterface.php ├── CacheManagerInterface.php ├── Directory.php ├── DirectoryInterface.php ├── FileCacheManager.php ├── FileHandler.php ├── FileHandlerInterface.php ├── NullCacheManager.php ├── Signature.php └── SignatureInterface.php ├── Config.php ├── ConfigInterface.php ├── ConfigurationException ├── InvalidConfigurationException.php ├── InvalidFixerConfigurationException.php ├── InvalidForEnvFixerConfigurationException.php └── RequiredFixerConfigurationException.php ├── Console ├── Application.php ├── Command │ ├── CheckCommand.php │ ├── DescribeCommand.php │ ├── DescribeNameNotFoundException.php │ ├── DocumentationCommand.php │ ├── FixCommand.php │ ├── FixCommandExitStatusCalculator.php │ ├── HelpCommand.php │ ├── ListFilesCommand.php │ ├── ListSetsCommand.php │ ├── SelfUpdateCommand.php │ └── WorkerCommand.php ├── ConfigurationResolver.php ├── Output │ ├── ErrorOutput.php │ ├── OutputContext.php │ └── Progress │ │ ├── DotsOutput.php │ │ ├── NullOutput.php │ │ ├── PercentageBarOutput.php │ │ ├── ProgressOutputFactory.php │ │ ├── ProgressOutputInterface.php │ │ └── ProgressOutputType.php ├── Report │ ├── FixReport │ │ ├── CheckstyleReporter.php │ │ ├── GitlabReporter.php │ │ ├── JsonReporter.php │ │ ├── JunitReporter.php │ │ ├── ReportSummary.php │ │ ├── ReporterFactory.php │ │ ├── ReporterInterface.php │ │ ├── TextReporter.php │ │ └── XmlReporter.php │ └── ListSetsReport │ │ ├── JsonReporter.php │ │ ├── ReportSummary.php │ │ ├── ReporterFactory.php │ │ ├── ReporterInterface.php │ │ └── TextReporter.php ├── SelfUpdate │ ├── GithubClient.php │ ├── GithubClientInterface.php │ ├── NewVersionChecker.php │ └── NewVersionCheckerInterface.php └── WarningsDetector.php ├── Differ ├── DiffConsoleFormatter.php ├── DifferInterface.php ├── FullDiffer.php ├── NullDiffer.php └── UnifiedDiffer.php ├── DocBlock ├── Annotation.php ├── DocBlock.php ├── Line.php ├── ShortDescription.php ├── Tag.php ├── TagComparator.php └── TypeExpression.php ├── Doctrine └── Annotation │ ├── DocLexer.php │ ├── Token.php │ └── Tokens.php ├── Documentation ├── DocumentationLocator.php ├── FixerDocumentGenerator.php ├── RstUtils.php └── RuleSetDocumentationGenerator.php ├── Error ├── Error.php ├── ErrorsManager.php └── SourceExceptionFactory.php ├── ExecutorWithoutErrorHandler.php ├── ExecutorWithoutErrorHandlerException.php ├── FileReader.php ├── FileRemoval.php ├── Finder.php ├── Fixer ├── AbstractIncrementOperatorFixer.php ├── AbstractPhpUnitFixer.php ├── AbstractShortOperatorFixer.php ├── Alias │ ├── ArrayPushFixer.php │ ├── BacktickToShellExecFixer.php │ ├── EregToPregFixer.php │ ├── MbStrFunctionsFixer.php │ ├── ModernizeStrposFixer.php │ ├── NoAliasFunctionsFixer.php │ ├── NoAliasLanguageConstructCallFixer.php │ ├── NoMixedEchoPrintFixer.php │ ├── PowToExponentiationFixer.php │ ├── RandomApiMigrationFixer.php │ └── SetTypeToCastFixer.php ├── ArrayNotation │ ├── ArraySyntaxFixer.php │ ├── NoMultilineWhitespaceAroundDoubleArrowFixer.php │ ├── NoTrailingCommaInSinglelineArrayFixer.php │ ├── NoWhitespaceBeforeCommaInArrayFixer.php │ ├── NormalizeIndexBraceFixer.php │ ├── ReturnToYieldFromFixer.php │ ├── TrimArraySpacesFixer.php │ ├── WhitespaceAfterCommaInArrayFixer.php │ └── YieldFromArrayToYieldsFixer.php ├── AttributeNotation │ ├── AttributeEmptyParenthesesFixer.php │ └── OrderedAttributesFixer.php ├── Basic │ ├── BracesFixer.php │ ├── BracesPositionFixer.php │ ├── CurlyBracesPositionFixer.php │ ├── EncodingFixer.php │ ├── NoMultipleStatementsPerLineFixer.php │ ├── NoTrailingCommaInSinglelineFixer.php │ ├── NonPrintableCharacterFixer.php │ ├── NumericLiteralSeparatorFixer.php │ ├── OctalNotationFixer.php │ ├── PsrAutoloadingFixer.php │ └── SingleLineEmptyBodyFixer.php ├── Casing │ ├── ClassReferenceNameCasingFixer.php │ ├── ConstantCaseFixer.php │ ├── IntegerLiteralCaseFixer.php │ ├── LowercaseKeywordsFixer.php │ ├── LowercaseStaticReferenceFixer.php │ ├── MagicConstantCasingFixer.php │ ├── MagicMethodCasingFixer.php │ ├── NativeFunctionCasingFixer.php │ ├── NativeFunctionTypeDeclarationCasingFixer.php │ └── NativeTypeDeclarationCasingFixer.php ├── CastNotation │ ├── CastSpacesFixer.php │ ├── LowercaseCastFixer.php │ ├── ModernizeTypesCastingFixer.php │ ├── NoShortBoolCastFixer.php │ ├── NoUnsetCastFixer.php │ └── ShortScalarCastFixer.php ├── ClassNotation │ ├── ClassAttributesSeparationFixer.php │ ├── ClassDefinitionFixer.php │ ├── FinalClassFixer.php │ ├── FinalInternalClassFixer.php │ ├── FinalPublicMethodForAbstractClassFixer.php │ ├── NoBlankLinesAfterClassOpeningFixer.php │ ├── NoNullPropertyInitializationFixer.php │ ├── NoPhp4ConstructorFixer.php │ ├── NoUnneededFinalMethodFixer.php │ ├── OrderedClassElementsFixer.php │ ├── OrderedInterfacesFixer.php │ ├── OrderedTraitsFixer.php │ ├── OrderedTypesFixer.php │ ├── PhpdocReadonlyClassCommentToKeywordFixer.php │ ├── ProtectedToPrivateFixer.php │ ├── SelfAccessorFixer.php │ ├── SelfStaticAccessorFixer.php │ ├── SingleClassElementPerStatementFixer.php │ ├── SingleTraitInsertPerStatementFixer.php │ └── VisibilityRequiredFixer.php ├── ClassUsage │ └── DateTimeImmutableFixer.php ├── Comment │ ├── CommentToPhpdocFixer.php │ ├── HeaderCommentFixer.php │ ├── MultilineCommentOpeningClosingFixer.php │ ├── NoEmptyCommentFixer.php │ ├── NoTrailingWhitespaceInCommentFixer.php │ ├── SingleLineCommentSpacingFixer.php │ └── SingleLineCommentStyleFixer.php ├── ConfigurableFixerInterface.php ├── ConstantNotation │ └── NativeConstantInvocationFixer.php ├── ControlStructure │ ├── ControlStructureBracesFixer.php │ ├── ControlStructureContinuationPositionFixer.php │ ├── ElseifFixer.php │ ├── EmptyLoopBodyFixer.php │ ├── EmptyLoopConditionFixer.php │ ├── IncludeFixer.php │ ├── NoAlternativeSyntaxFixer.php │ ├── NoBreakCommentFixer.php │ ├── NoSuperfluousElseifFixer.php │ ├── NoTrailingCommaInListCallFixer.php │ ├── NoUnneededBracesFixer.php │ ├── NoUnneededControlParenthesesFixer.php │ ├── NoUnneededCurlyBracesFixer.php │ ├── NoUselessElseFixer.php │ ├── SimplifiedIfReturnFixer.php │ ├── SwitchCaseSemicolonToColonFixer.php │ ├── SwitchCaseSpaceFixer.php │ ├── SwitchContinueToBreakFixer.php │ ├── TrailingCommaInMultilineFixer.php │ └── YodaStyleFixer.php ├── DeprecatedFixerInterface.php ├── DoctrineAnnotation │ ├── DoctrineAnnotationArrayAssignmentFixer.php │ ├── DoctrineAnnotationBracesFixer.php │ ├── DoctrineAnnotationIndentationFixer.php │ └── DoctrineAnnotationSpacesFixer.php ├── ExperimentalFixerInterface.php ├── FixerInterface.php ├── FunctionNotation │ ├── CombineNestedDirnameFixer.php │ ├── DateTimeCreateFromFormatCallFixer.php │ ├── FopenFlagOrderFixer.php │ ├── FopenFlagsFixer.php │ ├── FunctionDeclarationFixer.php │ ├── FunctionTypehintSpaceFixer.php │ ├── ImplodeCallFixer.php │ ├── LambdaNotUsedImportFixer.php │ ├── MethodArgumentSpaceFixer.php │ ├── NativeFunctionInvocationFixer.php │ ├── NoSpacesAfterFunctionNameFixer.php │ ├── NoTrailingCommaInSinglelineFunctionCallFixer.php │ ├── NoUnreachableDefaultArgumentValueFixer.php │ ├── NoUselessSprintfFixer.php │ ├── NullableTypeDeclarationForDefaultNullValueFixer.php │ ├── PhpdocToParamTypeFixer.php │ ├── PhpdocToPropertyTypeFixer.php │ ├── PhpdocToReturnTypeFixer.php │ ├── RegularCallableCallFixer.php │ ├── ReturnTypeDeclarationFixer.php │ ├── SingleLineThrowFixer.php │ ├── StaticLambdaFixer.php │ ├── UseArrowFunctionsFixer.php │ └── VoidReturnFixer.php ├── Import │ ├── FullyQualifiedStrictTypesFixer.php │ ├── GlobalNamespaceImportFixer.php │ ├── GroupImportFixer.php │ ├── NoLeadingImportSlashFixer.php │ ├── NoUnneededImportAliasFixer.php │ ├── NoUnusedImportsFixer.php │ ├── OrderedImportsFixer.php │ ├── SingleImportPerStatementFixer.php │ └── SingleLineAfterImportsFixer.php ├── Indentation.php ├── LanguageConstruct │ ├── ClassKeywordFixer.php │ ├── ClassKeywordRemoveFixer.php │ ├── CombineConsecutiveIssetsFixer.php │ ├── CombineConsecutiveUnsetsFixer.php │ ├── DeclareEqualNormalizeFixer.php │ ├── DeclareParenthesesFixer.php │ ├── DirConstantFixer.php │ ├── ErrorSuppressionFixer.php │ ├── ExplicitIndirectVariableFixer.php │ ├── FunctionToConstantFixer.php │ ├── GetClassToClassKeywordFixer.php │ ├── IsNullFixer.php │ ├── NoUnsetOnPropertyFixer.php │ ├── NullableTypeDeclarationFixer.php │ ├── SingleSpaceAfterConstructFixer.php │ └── SingleSpaceAroundConstructFixer.php ├── ListNotation │ └── ListSyntaxFixer.php ├── NamespaceNotation │ ├── BlankLineAfterNamespaceFixer.php │ ├── BlankLinesBeforeNamespaceFixer.php │ ├── CleanNamespaceFixer.php │ ├── NoBlankLinesBeforeNamespaceFixer.php │ ├── NoLeadingNamespaceWhitespaceFixer.php │ └── SingleBlankLineBeforeNamespaceFixer.php ├── Naming │ └── NoHomoglyphNamesFixer.php ├── Operator │ ├── AssignNullCoalescingToCoalesceEqualFixer.php │ ├── BinaryOperatorSpacesFixer.php │ ├── ConcatSpaceFixer.php │ ├── IncrementStyleFixer.php │ ├── LogicalOperatorsFixer.php │ ├── LongToShorthandOperatorFixer.php │ ├── NewWithBracesFixer.php │ ├── NewWithParenthesesFixer.php │ ├── NoSpaceAroundDoubleColonFixer.php │ ├── NoUselessConcatOperatorFixer.php │ ├── NoUselessNullsafeOperatorFixer.php │ ├── NotOperatorWithSpaceFixer.php │ ├── NotOperatorWithSuccessorSpaceFixer.php │ ├── ObjectOperatorWithoutWhitespaceFixer.php │ ├── OperatorLinebreakFixer.php │ ├── StandardizeIncrementFixer.php │ ├── StandardizeNotEqualsFixer.php │ ├── TernaryOperatorSpacesFixer.php │ ├── TernaryToElvisOperatorFixer.php │ ├── TernaryToNullCoalescingFixer.php │ └── UnaryOperatorSpacesFixer.php ├── PhpTag │ ├── BlankLineAfterOpeningTagFixer.php │ ├── EchoTagSyntaxFixer.php │ ├── FullOpeningTagFixer.php │ ├── LinebreakAfterOpeningTagFixer.php │ └── NoClosingTagFixer.php ├── PhpUnit │ ├── PhpUnitAttributesFixer.php │ ├── PhpUnitConstructFixer.php │ ├── PhpUnitDataProviderNameFixer.php │ ├── PhpUnitDataProviderReturnTypeFixer.php │ ├── PhpUnitDataProviderStaticFixer.php │ ├── PhpUnitDedicateAssertFixer.php │ ├── PhpUnitDedicateAssertInternalTypeFixer.php │ ├── PhpUnitExpectationFixer.php │ ├── PhpUnitFqcnAnnotationFixer.php │ ├── PhpUnitInternalClassFixer.php │ ├── PhpUnitMethodCasingFixer.php │ ├── PhpUnitMockFixer.php │ ├── PhpUnitMockShortWillReturnFixer.php │ ├── PhpUnitNamespacedFixer.php │ ├── PhpUnitNoExpectationAnnotationFixer.php │ ├── PhpUnitSetUpTearDownVisibilityFixer.php │ ├── PhpUnitSizeClassFixer.php │ ├── PhpUnitStrictFixer.php │ ├── PhpUnitTargetVersion.php │ ├── PhpUnitTestAnnotationFixer.php │ ├── PhpUnitTestCaseStaticMethodCallsFixer.php │ └── PhpUnitTestClassRequiresCoversFixer.php ├── Phpdoc │ ├── AlignMultilineCommentFixer.php │ ├── GeneralPhpdocAnnotationRemoveFixer.php │ ├── GeneralPhpdocTagRenameFixer.php │ ├── NoBlankLinesAfterPhpdocFixer.php │ ├── NoEmptyPhpdocFixer.php │ ├── NoSuperfluousPhpdocTagsFixer.php │ ├── PhpdocAddMissingParamAnnotationFixer.php │ ├── PhpdocAlignFixer.php │ ├── PhpdocAnnotationWithoutDotFixer.php │ ├── PhpdocArrayTypeFixer.php │ ├── PhpdocIndentFixer.php │ ├── PhpdocInlineTagNormalizerFixer.php │ ├── PhpdocLineSpanFixer.php │ ├── PhpdocListTypeFixer.php │ ├── PhpdocNoAccessFixer.php │ ├── PhpdocNoAliasTagFixer.php │ ├── PhpdocNoEmptyReturnFixer.php │ ├── PhpdocNoPackageFixer.php │ ├── PhpdocNoUselessInheritdocFixer.php │ ├── PhpdocOrderByValueFixer.php │ ├── PhpdocOrderFixer.php │ ├── PhpdocParamOrderFixer.php │ ├── PhpdocReturnSelfReferenceFixer.php │ ├── PhpdocScalarFixer.php │ ├── PhpdocSeparationFixer.php │ ├── PhpdocSingleLineVarSpacingFixer.php │ ├── PhpdocSummaryFixer.php │ ├── PhpdocTagCasingFixer.php │ ├── PhpdocTagTypeFixer.php │ ├── PhpdocToCommentFixer.php │ ├── PhpdocTrimConsecutiveBlankLineSeparationFixer.php │ ├── PhpdocTrimFixer.php │ ├── PhpdocTypesFixer.php │ ├── PhpdocTypesOrderFixer.php │ ├── PhpdocVarAnnotationCorrectOrderFixer.php │ └── PhpdocVarWithoutNameFixer.php ├── ReturnNotation │ ├── NoUselessReturnFixer.php │ ├── ReturnAssignmentFixer.php │ └── SimplifiedNullReturnFixer.php ├── Semicolon │ ├── MultilineWhitespaceBeforeSemicolonsFixer.php │ ├── NoEmptyStatementFixer.php │ ├── NoSinglelineWhitespaceBeforeSemicolonsFixer.php │ ├── SemicolonAfterInstructionFixer.php │ └── SpaceAfterSemicolonFixer.php ├── Strict │ ├── DeclareStrictTypesFixer.php │ ├── StrictComparisonFixer.php │ └── StrictParamFixer.php ├── StringNotation │ ├── EscapeImplicitBackslashesFixer.php │ ├── ExplicitStringVariableFixer.php │ ├── HeredocClosingMarkerFixer.php │ ├── HeredocToNowdocFixer.php │ ├── MultilineStringToHeredocFixer.php │ ├── NoBinaryStringFixer.php │ ├── NoTrailingWhitespaceInStringFixer.php │ ├── SimpleToComplexStringVariableFixer.php │ ├── SingleQuoteFixer.php │ ├── StringImplicitBackslashesFixer.php │ ├── StringLengthToEmptyFixer.php │ └── StringLineEndingFixer.php ├── Whitespace │ ├── ArrayIndentationFixer.php │ ├── BlankLineBeforeStatementFixer.php │ ├── BlankLineBetweenImportGroupsFixer.php │ ├── CompactNullableTypeDeclarationFixer.php │ ├── CompactNullableTypehintFixer.php │ ├── HeredocIndentationFixer.php │ ├── IndentationTypeFixer.php │ ├── LineEndingFixer.php │ ├── MethodChainingIndentationFixer.php │ ├── NoExtraBlankLinesFixer.php │ ├── NoSpacesAroundOffsetFixer.php │ ├── NoSpacesInsideParenthesisFixer.php │ ├── NoTrailingWhitespaceFixer.php │ ├── NoWhitespaceInBlankLineFixer.php │ ├── SingleBlankLineAtEofFixer.php │ ├── SpacesInsideParenthesesFixer.php │ ├── StatementIndentationFixer.php │ ├── TypeDeclarationSpacesFixer.php │ └── TypesSpacesFixer.php └── WhitespacesAwareFixerInterface.php ├── FixerConfiguration ├── AliasedFixerOption.php ├── AliasedFixerOptionBuilder.php ├── AllowedValueSubset.php ├── DeprecatedFixerOption.php ├── DeprecatedFixerOptionInterface.php ├── FixerConfigurationResolver.php ├── FixerConfigurationResolverInterface.php ├── FixerOption.php ├── FixerOptionBuilder.php ├── FixerOptionInterface.php ├── FixerOptionSorter.php └── InvalidOptionsForEnvException.php ├── FixerDefinition ├── CodeSample.php ├── CodeSampleInterface.php ├── FileSpecificCodeSample.php ├── FileSpecificCodeSampleInterface.php ├── FixerDefinition.php ├── FixerDefinitionInterface.php ├── VersionSpecificCodeSample.php ├── VersionSpecificCodeSampleInterface.php ├── VersionSpecification.php └── VersionSpecificationInterface.php ├── FixerFactory.php ├── FixerFileProcessedEvent.php ├── FixerNameValidator.php ├── Indicator └── PhpUnitTestCaseIndicator.php ├── Linter ├── CachingLinter.php ├── Linter.php ├── LinterInterface.php ├── LintingException.php ├── LintingResultInterface.php ├── ProcessLinter.php ├── ProcessLinterProcessBuilder.php ├── ProcessLintingResult.php ├── TokenizerLinter.php ├── TokenizerLintingResult.php └── UnavailableLinterException.php ├── ParallelAwareConfigInterface.php ├── PharChecker.php ├── PharCheckerInterface.php ├── Preg.php ├── PregException.php ├── RuleSet ├── AbstractMigrationSetDescription.php ├── AbstractRuleSetDescription.php ├── DeprecatedRuleSetDescriptionInterface.php ├── RuleSet.php ├── RuleSetDescriptionInterface.php ├── RuleSetInterface.php ├── RuleSets.php └── Sets │ ├── DoctrineAnnotationSet.php │ ├── PERCS1x0RiskySet.php │ ├── PERCS1x0Set.php │ ├── PERCS2x0RiskySet.php │ ├── PERCS2x0Set.php │ ├── PERCSRiskySet.php │ ├── PERCSSet.php │ ├── PERRiskySet.php │ ├── PERSet.php │ ├── PHP54MigrationSet.php │ ├── PHP56MigrationRiskySet.php │ ├── PHP70MigrationRiskySet.php │ ├── PHP70MigrationSet.php │ ├── PHP71MigrationRiskySet.php │ ├── PHP71MigrationSet.php │ ├── PHP73MigrationSet.php │ ├── PHP74MigrationRiskySet.php │ ├── PHP74MigrationSet.php │ ├── PHP80MigrationRiskySet.php │ ├── PHP80MigrationSet.php │ ├── PHP81MigrationSet.php │ ├── PHP82MigrationSet.php │ ├── PHP83MigrationSet.php │ ├── PHP84MigrationSet.php │ ├── PHPUnit100MigrationRiskySet.php │ ├── PHPUnit30MigrationRiskySet.php │ ├── PHPUnit32MigrationRiskySet.php │ ├── PHPUnit35MigrationRiskySet.php │ ├── PHPUnit43MigrationRiskySet.php │ ├── PHPUnit48MigrationRiskySet.php │ ├── PHPUnit50MigrationRiskySet.php │ ├── PHPUnit52MigrationRiskySet.php │ ├── PHPUnit54MigrationRiskySet.php │ ├── PHPUnit55MigrationRiskySet.php │ ├── PHPUnit56MigrationRiskySet.php │ ├── PHPUnit57MigrationRiskySet.php │ ├── PHPUnit60MigrationRiskySet.php │ ├── PHPUnit75MigrationRiskySet.php │ ├── PHPUnit84MigrationRiskySet.php │ ├── PSR12RiskySet.php │ ├── PSR12Set.php │ ├── PSR1Set.php │ ├── PSR2Set.php │ ├── PhpCsFixerRiskySet.php │ ├── PhpCsFixerSet.php │ ├── SymfonyRiskySet.php │ └── SymfonySet.php ├── Runner ├── FileCachingLintingFileIterator.php ├── FileFilterIterator.php ├── LintingFileIterator.php ├── LintingResultAwareFileIteratorInterface.php ├── Parallel │ ├── ParallelAction.php │ ├── ParallelConfig.php │ ├── ParallelConfigFactory.php │ ├── ParallelisationException.php │ ├── Process.php │ ├── ProcessFactory.php │ ├── ProcessIdentifier.php │ ├── ProcessPool.php │ └── WorkerException.php ├── Runner.php └── RunnerConfig.php ├── StdinFileInfo.php ├── Tokenizer ├── AbstractTransformer.php ├── AbstractTypeTransformer.php ├── Analyzer │ ├── AlternativeSyntaxAnalyzer.php │ ├── Analysis │ │ ├── AbstractControlCaseStructuresAnalysis.php │ │ ├── ArgumentAnalysis.php │ │ ├── AttributeAnalysis.php │ │ ├── CaseAnalysis.php │ │ ├── DataProviderAnalysis.php │ │ ├── DefaultAnalysis.php │ │ ├── EnumAnalysis.php │ │ ├── MatchAnalysis.php │ │ ├── NamespaceAnalysis.php │ │ ├── NamespaceUseAnalysis.php │ │ ├── StartEndTokenAwareAnalysis.php │ │ ├── SwitchAnalysis.php │ │ └── TypeAnalysis.php │ ├── ArgumentsAnalyzer.php │ ├── AttributeAnalyzer.php │ ├── BlocksAnalyzer.php │ ├── ClassyAnalyzer.php │ ├── CommentsAnalyzer.php │ ├── ControlCaseStructuresAnalyzer.php │ ├── DataProviderAnalyzer.php │ ├── FunctionsAnalyzer.php │ ├── GotoLabelAnalyzer.php │ ├── NamespaceUsesAnalyzer.php │ ├── NamespacesAnalyzer.php │ ├── RangeAnalyzer.php │ ├── ReferenceAnalyzer.php │ ├── SwitchAnalyzer.php │ └── WhitespacesAnalyzer.php ├── CT.php ├── CodeHasher.php ├── Processor │ └── ImportProcessor.php ├── Token.php ├── Tokens.php ├── TokensAnalyzer.php ├── Transformer │ ├── ArrayTypehintTransformer.php │ ├── AttributeTransformer.php │ ├── BraceClassInstantiationTransformer.php │ ├── BraceTransformer.php │ ├── ClassConstantTransformer.php │ ├── ConstructorPromotionTransformer.php │ ├── DisjunctiveNormalFormTypeParenthesisTransformer.php │ ├── FirstClassCallableTransformer.php │ ├── ImportTransformer.php │ ├── NameQualifiedTransformer.php │ ├── NamedArgumentTransformer.php │ ├── NamespaceOperatorTransformer.php │ ├── NullableTypeTransformer.php │ ├── ReturnRefTransformer.php │ ├── SquareBraceTransformer.php │ ├── TypeAlternationTransformer.php │ ├── TypeColonTransformer.php │ ├── TypeIntersectionTransformer.php │ ├── UseTransformer.php │ └── WhitespacyCommentTransformer.php ├── TransformerInterface.php └── Transformers.php ├── ToolInfo.php ├── ToolInfoInterface.php ├── Utils.php ├── WhitespacesFixerConfig.php └── WordMatcher.php /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012+ Fabien Potencier, Dariusz Rumiński 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /ci-integration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | IFS=' 5 | ' 6 | CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "${COMMIT_RANGE}") 7 | if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi 8 | vendor/bin/php-cs-fixer check --config=.php-cs-fixer.dist.php -v --show-progress=dots --stop-on-violation --using-cache=no ${EXTRA_ARGS} 9 | -------------------------------------------------------------------------------- /feature-or-bug.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Is it a feature or a bug ? 3 | ========================== 4 | 5 | Sometimes it's a bit tricky to define if given change proposal or change request is adding new feature or fixing existing issue. This document is providing more clarity about categorisation we use. 6 | 7 | Bug 8 | --- 9 | 10 | Example of bugs: 11 | 12 | - crash during application or rule execution 13 | - wrong changes are applied during "fixing codebase" process 14 | - issue with generated report 15 | 16 | Feature 17 | ------- 18 | 19 | Example of features: 20 | 21 | - introduction of new rule 22 | - enhancement of existing rule to cover more cases (for example adding support for newly introduced PHP syntax) 23 | - introduction of new ruleset 24 | - update of existing ruleset (for example adjusting it to match newest style of given community or adding newly implemented rule that was supposed to be followed by style of given community, yet not implemented as a rule before) 25 | -------------------------------------------------------------------------------- /logo.md: -------------------------------------------------------------------------------- 1 | The logo is © 2010+ Sensio Labs. 2 | 3 | Original resolution can be found at . 4 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vdegteva23/PHP-CS-Fixer/08bc02ca64de12ad946b92312fe0fda1706f8394/logo.png -------------------------------------------------------------------------------- /src/Cache/CacheInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Cache; 16 | 17 | /** 18 | * @author Andreas Möller 19 | * 20 | * @internal 21 | */ 22 | interface CacheInterface 23 | { 24 | public function getSignature(): SignatureInterface; 25 | 26 | public function has(string $file): bool; 27 | 28 | public function get(string $file): ?string; 29 | 30 | public function set(string $file, string $hash): void; 31 | 32 | public function clear(string $file): void; 33 | 34 | public function toJson(): string; 35 | } 36 | -------------------------------------------------------------------------------- /src/Cache/CacheManagerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Cache; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | interface CacheManagerInterface 23 | { 24 | public function needFixing(string $file, string $fileContent): bool; 25 | 26 | public function setFile(string $file, string $fileContent): void; 27 | 28 | public function setFileHash(string $file, string $hash): void; 29 | } 30 | -------------------------------------------------------------------------------- /src/Cache/Directory.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Cache; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class Directory implements DirectoryInterface 23 | { 24 | private string $directoryName; 25 | 26 | public function __construct(string $directoryName) 27 | { 28 | $this->directoryName = $directoryName; 29 | } 30 | 31 | public function getRelativePathTo(string $file): string 32 | { 33 | $file = $this->normalizePath($file); 34 | 35 | if ( 36 | '' === $this->directoryName 37 | || 0 !== stripos($file, $this->directoryName.\DIRECTORY_SEPARATOR) 38 | ) { 39 | return $file; 40 | } 41 | 42 | return substr($file, \strlen($this->directoryName) + 1); 43 | } 44 | 45 | private function normalizePath(string $path): string 46 | { 47 | return str_replace(['\\', '/'], \DIRECTORY_SEPARATOR, $path); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Cache/DirectoryInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Cache; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | */ 20 | interface DirectoryInterface 21 | { 22 | public function getRelativePathTo(string $file): string; 23 | } 24 | -------------------------------------------------------------------------------- /src/Cache/FileHandlerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Cache; 16 | 17 | /** 18 | * @author Andreas Möller 19 | * 20 | * @internal 21 | */ 22 | interface FileHandlerInterface 23 | { 24 | public function getFile(): string; 25 | 26 | public function read(): ?CacheInterface; 27 | 28 | public function write(CacheInterface $cache): void; 29 | } 30 | -------------------------------------------------------------------------------- /src/Cache/NullCacheManager.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Cache; 16 | 17 | /** 18 | * @author Andreas Möller 19 | * @author Dariusz Rumiński 20 | * 21 | * @internal 22 | */ 23 | final class NullCacheManager implements CacheManagerInterface 24 | { 25 | public function needFixing(string $file, string $fileContent): bool 26 | { 27 | return true; 28 | } 29 | 30 | public function setFile(string $file, string $fileContent): void {} 31 | 32 | public function setFileHash(string $file, string $hash): void {} 33 | } 34 | -------------------------------------------------------------------------------- /src/Cache/SignatureInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Cache; 16 | 17 | /** 18 | * @author Andreas Möller 19 | * 20 | * @internal 21 | */ 22 | interface SignatureInterface 23 | { 24 | public function getPhpVersion(): string; 25 | 26 | public function getFixerVersion(): string; 27 | 28 | public function getIndent(): string; 29 | 30 | public function getLineEnding(): string; 31 | 32 | /** 33 | * @return array|bool> 34 | */ 35 | public function getRules(): array; 36 | 37 | public function equals(self $signature): bool; 38 | } 39 | -------------------------------------------------------------------------------- /src/ConfigurationException/InvalidConfigurationException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\ConfigurationException; 16 | 17 | use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator; 18 | 19 | /** 20 | * Exceptions of this type are thrown on misconfiguration of the Fixer. 21 | * 22 | * @internal 23 | * 24 | * @final Only internal extending this class is supported 25 | */ 26 | class InvalidConfigurationException extends \InvalidArgumentException 27 | { 28 | public function __construct(string $message, ?int $code = null, ?\Throwable $previous = null) 29 | { 30 | parent::__construct( 31 | $message, 32 | $code ?? FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG, 33 | $previous 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/ConfigurationException/InvalidFixerConfigurationException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\ConfigurationException; 16 | 17 | use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator; 18 | 19 | /** 20 | * Exception thrown by Fixers on misconfiguration. 21 | * 22 | * @internal 23 | * 24 | * @final Only internal extending this class is supported 25 | */ 26 | class InvalidFixerConfigurationException extends InvalidConfigurationException 27 | { 28 | private string $fixerName; 29 | 30 | public function __construct(string $fixerName, string $message, ?\Throwable $previous = null) 31 | { 32 | parent::__construct( 33 | sprintf('[%s] %s', $fixerName, $message), 34 | FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, 35 | $previous 36 | ); 37 | 38 | $this->fixerName = $fixerName; 39 | } 40 | 41 | public function getFixerName(): string 42 | { 43 | return $this->fixerName; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/ConfigurationException/InvalidForEnvFixerConfigurationException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\ConfigurationException; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class InvalidForEnvFixerConfigurationException extends InvalidFixerConfigurationException {} 23 | -------------------------------------------------------------------------------- /src/ConfigurationException/RequiredFixerConfigurationException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\ConfigurationException; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class RequiredFixerConfigurationException extends InvalidFixerConfigurationException {} 23 | -------------------------------------------------------------------------------- /src/Console/Command/DescribeNameNotFoundException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Command; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class DescribeNameNotFoundException extends \InvalidArgumentException 21 | { 22 | private string $name; 23 | 24 | /** 25 | * 'rule'|'set'. 26 | */ 27 | private string $type; 28 | 29 | public function __construct(string $name, string $type) 30 | { 31 | $this->name = $name; 32 | $this->type = $type; 33 | 34 | parent::__construct(); 35 | } 36 | 37 | public function getName(): string 38 | { 39 | return $this->name; 40 | } 41 | 42 | public function getType(): string 43 | { 44 | return $this->type; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Console/Command/FixCommandExitStatusCalculator.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Command; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class FixCommandExitStatusCalculator 23 | { 24 | // Exit status 1 is reserved for environment constraints not matched. 25 | public const EXIT_STATUS_FLAG_HAS_INVALID_FILES = 4; 26 | public const EXIT_STATUS_FLAG_HAS_CHANGED_FILES = 8; 27 | public const EXIT_STATUS_FLAG_HAS_INVALID_CONFIG = 16; 28 | public const EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG = 32; 29 | public const EXIT_STATUS_FLAG_EXCEPTION_IN_APP = 64; 30 | 31 | public function calculate( 32 | bool $isDryRun, 33 | bool $hasChangedFiles, 34 | bool $hasInvalidErrors, 35 | bool $hasExceptionErrors, 36 | bool $hasLintErrorsAfterFixing 37 | ): int { 38 | $exitStatus = 0; 39 | 40 | if ($isDryRun) { 41 | if ($hasChangedFiles) { 42 | $exitStatus |= self::EXIT_STATUS_FLAG_HAS_CHANGED_FILES; 43 | } 44 | 45 | if ($hasInvalidErrors) { 46 | $exitStatus |= self::EXIT_STATUS_FLAG_HAS_INVALID_FILES; 47 | } 48 | } 49 | 50 | if ($hasExceptionErrors || $hasLintErrorsAfterFixing) { 51 | $exitStatus |= self::EXIT_STATUS_FLAG_EXCEPTION_IN_APP; 52 | } 53 | 54 | return $exitStatus; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Console/Output/OutputContext.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Output; 16 | 17 | use Symfony\Component\Console\Output\OutputInterface; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class OutputContext 23 | { 24 | private ?OutputInterface $output; 25 | private int $terminalWidth; 26 | private int $filesCount; 27 | 28 | public function __construct( 29 | ?OutputInterface $output, 30 | int $terminalWidth, 31 | int $filesCount 32 | ) { 33 | $this->output = $output; 34 | $this->terminalWidth = $terminalWidth; 35 | $this->filesCount = $filesCount; 36 | } 37 | 38 | public function getOutput(): ?OutputInterface 39 | { 40 | return $this->output; 41 | } 42 | 43 | public function getTerminalWidth(): int 44 | { 45 | return $this->terminalWidth; 46 | } 47 | 48 | public function getFilesCount(): int 49 | { 50 | return $this->filesCount; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Console/Output/Progress/NullOutput.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Output\Progress; 16 | 17 | use PhpCsFixer\FixerFileProcessedEvent; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class NullOutput implements ProgressOutputInterface 23 | { 24 | public function printLegend(): void {} 25 | 26 | public function onFixerFileProcessed(FixerFileProcessedEvent $event): void {} 27 | } 28 | -------------------------------------------------------------------------------- /src/Console/Output/Progress/ProgressOutputFactory.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Output\Progress; 16 | 17 | use PhpCsFixer\Console\Output\OutputContext; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class ProgressOutputFactory 23 | { 24 | /** 25 | * @var array> 26 | */ 27 | private static array $outputTypeMap = [ 28 | ProgressOutputType::NONE => NullOutput::class, 29 | ProgressOutputType::DOTS => DotsOutput::class, 30 | ProgressOutputType::BAR => PercentageBarOutput::class, 31 | ]; 32 | 33 | public function create(string $outputType, OutputContext $context): ProgressOutputInterface 34 | { 35 | if (null === $context->getOutput()) { 36 | $outputType = ProgressOutputType::NONE; 37 | } 38 | 39 | if (!$this->isBuiltInType($outputType)) { 40 | throw new \InvalidArgumentException( 41 | sprintf( 42 | 'Something went wrong, "%s" output type is not supported', 43 | $outputType 44 | ) 45 | ); 46 | } 47 | 48 | return new self::$outputTypeMap[$outputType]($context); 49 | } 50 | 51 | private function isBuiltInType(string $outputType): bool 52 | { 53 | return \in_array($outputType, ProgressOutputType::all(), true); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Console/Output/Progress/ProgressOutputInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Output\Progress; 16 | 17 | use PhpCsFixer\FixerFileProcessedEvent; 18 | 19 | /** 20 | * @internal 21 | */ 22 | interface ProgressOutputInterface 23 | { 24 | public function printLegend(): void; 25 | 26 | public function onFixerFileProcessed(FixerFileProcessedEvent $event): void; 27 | } 28 | -------------------------------------------------------------------------------- /src/Console/Output/Progress/ProgressOutputType.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Output\Progress; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class ProgressOutputType 21 | { 22 | public const NONE = 'none'; 23 | public const DOTS = 'dots'; 24 | public const BAR = 'bar'; 25 | 26 | /** 27 | * @return list 28 | */ 29 | public static function all(): array 30 | { 31 | return [ 32 | self::BAR, 33 | self::DOTS, 34 | self::NONE, 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Console/Report/FixReport/JsonReporter.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Report\FixReport; 16 | 17 | use PhpCsFixer\Console\Application; 18 | use Symfony\Component\Console\Formatter\OutputFormatter; 19 | 20 | /** 21 | * @author Boris Gorbylev 22 | * 23 | * @internal 24 | */ 25 | final class JsonReporter implements ReporterInterface 26 | { 27 | public function getFormat(): string 28 | { 29 | return 'json'; 30 | } 31 | 32 | public function generate(ReportSummary $reportSummary): string 33 | { 34 | $jsonFiles = []; 35 | 36 | foreach ($reportSummary->getChanged() as $file => $fixResult) { 37 | $jsonFile = ['name' => $file]; 38 | 39 | if ($reportSummary->shouldAddAppliedFixers()) { 40 | $jsonFile['appliedFixers'] = $fixResult['appliedFixers']; 41 | } 42 | 43 | if ('' !== $fixResult['diff']) { 44 | $jsonFile['diff'] = $fixResult['diff']; 45 | } 46 | 47 | $jsonFiles[] = $jsonFile; 48 | } 49 | 50 | $json = [ 51 | 'about' => Application::getAbout(), 52 | 'files' => $jsonFiles, 53 | 'time' => [ 54 | 'total' => round($reportSummary->getTime() / 1_000, 3), 55 | ], 56 | 'memory' => round($reportSummary->getMemory() / 1_024 / 1_024, 3), 57 | ]; 58 | 59 | $json = json_encode($json, JSON_THROW_ON_ERROR); 60 | 61 | return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($json) : $json; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Console/Report/FixReport/ReporterInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Report\FixReport; 16 | 17 | /** 18 | * @author Boris Gorbylev 19 | * 20 | * @internal 21 | */ 22 | interface ReporterInterface 23 | { 24 | public function getFormat(): string; 25 | 26 | /** 27 | * Process changed files array. Returns generated report. 28 | */ 29 | public function generate(ReportSummary $reportSummary): string; 30 | } 31 | -------------------------------------------------------------------------------- /src/Console/Report/ListSetsReport/JsonReporter.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Report\ListSetsReport; 16 | 17 | use PhpCsFixer\RuleSet\RuleSetDescriptionInterface; 18 | 19 | /** 20 | * @author Dariusz Rumiński 21 | * 22 | * @internal 23 | */ 24 | final class JsonReporter implements ReporterInterface 25 | { 26 | public function getFormat(): string 27 | { 28 | return 'json'; 29 | } 30 | 31 | public function generate(ReportSummary $reportSummary): string 32 | { 33 | $sets = $reportSummary->getSets(); 34 | 35 | usort($sets, static fn (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b): int => $a->getName() <=> $b->getName()); 36 | 37 | $json = ['sets' => []]; 38 | 39 | foreach ($sets as $set) { 40 | $setName = $set->getName(); 41 | $json['sets'][$setName] = [ 42 | 'description' => $set->getDescription(), 43 | 'isRisky' => $set->isRisky(), 44 | 'name' => $setName, 45 | ]; 46 | } 47 | 48 | return json_encode($json, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Console/Report/ListSetsReport/ReportSummary.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Report\ListSetsReport; 16 | 17 | use PhpCsFixer\RuleSet\RuleSetDescriptionInterface; 18 | 19 | /** 20 | * @author Dariusz Rumiński 21 | * 22 | * @internal 23 | */ 24 | final class ReportSummary 25 | { 26 | /** 27 | * @var list 28 | */ 29 | private array $sets; 30 | 31 | /** 32 | * @param list $sets 33 | */ 34 | public function __construct(array $sets) 35 | { 36 | $this->sets = $sets; 37 | } 38 | 39 | /** 40 | * @return list 41 | */ 42 | public function getSets(): array 43 | { 44 | return $this->sets; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Console/Report/ListSetsReport/ReporterInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Report\ListSetsReport; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | interface ReporterInterface 23 | { 24 | public function getFormat(): string; 25 | 26 | /** 27 | * Process changed files array. Returns generated report. 28 | */ 29 | public function generate(ReportSummary $reportSummary): string; 30 | } 31 | -------------------------------------------------------------------------------- /src/Console/Report/ListSetsReport/TextReporter.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\Report\ListSetsReport; 16 | 17 | use PhpCsFixer\RuleSet\RuleSetDescriptionInterface; 18 | 19 | /** 20 | * @author Dariusz Rumiński 21 | * 22 | * @internal 23 | */ 24 | final class TextReporter implements ReporterInterface 25 | { 26 | public function getFormat(): string 27 | { 28 | return 'txt'; 29 | } 30 | 31 | public function generate(ReportSummary $reportSummary): string 32 | { 33 | $sets = $reportSummary->getSets(); 34 | 35 | usort($sets, static fn (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b): int => $a->getName() <=> $b->getName()); 36 | 37 | $output = ''; 38 | 39 | foreach ($sets as $i => $set) { 40 | $output .= sprintf('%2d) %s', $i + 1, $set->getName()).PHP_EOL.' '.$set->getDescription().PHP_EOL; 41 | 42 | if ($set->isRisky()) { 43 | $output .= ' Set contains risky rules.'.PHP_EOL; 44 | } 45 | } 46 | 47 | return $output; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Console/SelfUpdate/GithubClient.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\SelfUpdate; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class GithubClient implements GithubClientInterface 21 | { 22 | private string $url = 'https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/tags'; 23 | 24 | public function getTags(): array 25 | { 26 | $result = @file_get_contents( 27 | $this->url, 28 | false, 29 | stream_context_create([ 30 | 'http' => [ 31 | 'header' => 'User-Agent: PHP-CS-Fixer/PHP-CS-Fixer', 32 | ], 33 | ]) 34 | ); 35 | 36 | if (false === $result) { 37 | throw new \RuntimeException(sprintf('Failed to load tags at "%s".', $this->url)); 38 | } 39 | 40 | /** 41 | * @var list 47 | */ 48 | $result = json_decode($result, true); 49 | if (JSON_ERROR_NONE !== json_last_error()) { 50 | throw new \RuntimeException(sprintf( 51 | 'Failed to read response from "%s" as JSON: %s.', 52 | $this->url, 53 | json_last_error_msg() 54 | )); 55 | } 56 | 57 | return array_map( 58 | static fn (array $tagData): string => $tagData['name'], 59 | $result 60 | ); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Console/SelfUpdate/GithubClientInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\SelfUpdate; 16 | 17 | /** 18 | * @internal 19 | */ 20 | interface GithubClientInterface 21 | { 22 | /** 23 | * @return list 24 | */ 25 | public function getTags(): array; 26 | } 27 | -------------------------------------------------------------------------------- /src/Console/SelfUpdate/NewVersionCheckerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Console\SelfUpdate; 16 | 17 | /** 18 | * @internal 19 | */ 20 | interface NewVersionCheckerInterface 21 | { 22 | /** 23 | * Returns the tag of the latest version. 24 | */ 25 | public function getLatestVersion(): string; 26 | 27 | /** 28 | * Returns the tag of the latest minor/patch version of the given major version. 29 | */ 30 | public function getLatestVersionOfMajor(int $majorVersion): ?string; 31 | 32 | /** 33 | * Returns -1, 0, or 1 if the first version is respectively less than, 34 | * equal to, or greater than the second. 35 | */ 36 | public function compareVersions(string $versionA, string $versionB): int; 37 | } 38 | -------------------------------------------------------------------------------- /src/Differ/DifferInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Differ; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | */ 20 | interface DifferInterface 21 | { 22 | /** 23 | * Create diff. 24 | */ 25 | public function diff(string $old, string $new, ?\SplFileInfo $file = null): string; 26 | } 27 | -------------------------------------------------------------------------------- /src/Differ/FullDiffer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Differ; 16 | 17 | use SebastianBergmann\Diff\Differ; 18 | use SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder; 19 | 20 | /** 21 | * @author Dariusz Rumiński 22 | * 23 | * @internal 24 | */ 25 | final class FullDiffer implements DifferInterface 26 | { 27 | private Differ $differ; 28 | 29 | public function __construct() 30 | { 31 | $this->differ = new Differ(new StrictUnifiedDiffOutputBuilder([ 32 | 'collapseRanges' => false, 33 | 'commonLineThreshold' => 100, 34 | 'contextLines' => 100, 35 | 'fromFile' => 'Original', 36 | 'toFile' => 'New', 37 | ])); 38 | } 39 | 40 | public function diff(string $old, string $new, ?\SplFileInfo $file = null): string 41 | { 42 | return $this->differ->diff($old, $new); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Differ/NullDiffer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Differ; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | */ 20 | final class NullDiffer implements DifferInterface 21 | { 22 | public function diff(string $old, string $new, ?\SplFileInfo $file = null): string 23 | { 24 | return ''; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Differ/UnifiedDiffer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Differ; 16 | 17 | use PhpCsFixer\Preg; 18 | use SebastianBergmann\Diff\Differ; 19 | use SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder; 20 | 21 | final class UnifiedDiffer implements DifferInterface 22 | { 23 | public function diff(string $old, string $new, ?\SplFileInfo $file = null): string 24 | { 25 | if (null === $file) { 26 | $options = [ 27 | 'fromFile' => 'Original', 28 | 'toFile' => 'New', 29 | ]; 30 | } else { 31 | $filePath = $file->getRealPath(); 32 | 33 | if (Preg::match('/\s/', $filePath)) { 34 | $filePath = '"'.$filePath.'"'; 35 | } 36 | 37 | $options = [ 38 | 'fromFile' => $filePath, 39 | 'toFile' => $filePath, 40 | ]; 41 | } 42 | 43 | $differ = new Differ(new StrictUnifiedDiffOutputBuilder($options)); 44 | 45 | return $differ->diff($old, $new); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/DocBlock/ShortDescription.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\DocBlock; 16 | 17 | /** 18 | * This class represents a short description (aka summary) of a docblock. 19 | * 20 | * @internal 21 | */ 22 | final class ShortDescription 23 | { 24 | /** 25 | * The docblock containing the short description. 26 | */ 27 | private DocBlock $doc; 28 | 29 | public function __construct(DocBlock $doc) 30 | { 31 | $this->doc = $doc; 32 | } 33 | 34 | /** 35 | * Get the line index of the line containing the end of the short 36 | * description, if present. 37 | */ 38 | public function getEnd(): ?int 39 | { 40 | $reachedContent = false; 41 | 42 | foreach ($this->doc->getLines() as $index => $line) { 43 | // we went past a description, then hit a tag or blank line, so 44 | // the last line of the description must be the one before this one 45 | if ($reachedContent && ($line->containsATag() || !$line->containsUsefulContent())) { 46 | return $index - 1; 47 | } 48 | 49 | // no short description was found 50 | if ($line->containsATag()) { 51 | return null; 52 | } 53 | 54 | // we've reached content, but need to check the next lines too 55 | // in case the short description is multi-line 56 | if ($line->containsUsefulContent()) { 57 | $reachedContent = true; 58 | } 59 | } 60 | 61 | return null; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Documentation/RstUtils.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Documentation; 16 | 17 | use PhpCsFixer\Preg; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class RstUtils 23 | { 24 | private function __construct() 25 | { 26 | // cannot create instance of util. class 27 | } 28 | 29 | public static function toRst(string $string, int $indent = 0): string 30 | { 31 | $string = wordwrap(self::ensureProperInlineCode($string), 80 - $indent); 32 | 33 | return 0 === $indent ? $string : self::indent($string, $indent); 34 | } 35 | 36 | public static function ensureProperInlineCode(string $string): string 37 | { 38 | return Preg::replace('/(? 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class ExecutorWithoutErrorHandler 23 | { 24 | private function __construct() {} 25 | 26 | /** 27 | * @template T 28 | * 29 | * @param callable(): T $callback 30 | * 31 | * @return T 32 | * 33 | * @throws ExecutorWithoutErrorHandlerException 34 | */ 35 | public static function execute(callable $callback) 36 | { 37 | /** @var ?string */ 38 | $error = null; 39 | 40 | set_error_handler(static function (int $errorNumber, string $errorString, string $errorFile, int $errorLine) use (&$error): bool { 41 | $error = $errorString; 42 | 43 | return true; 44 | }); 45 | 46 | try { 47 | $result = $callback(); 48 | } finally { 49 | restore_error_handler(); 50 | } 51 | 52 | if (null !== $error) { 53 | throw new ExecutorWithoutErrorHandlerException($error); 54 | } 55 | 56 | return $result; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/ExecutorWithoutErrorHandlerException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class ExecutorWithoutErrorHandlerException extends \RuntimeException {} 23 | -------------------------------------------------------------------------------- /src/FileReader.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * File reader that unify access to regular file and stdin-alike file. 19 | * 20 | * Regular file could be read multiple times with `file_get_contents`, but file provided on stdin cannot. 21 | * Consecutive try will provide empty content for stdin-alike file. 22 | * This reader unifies access to them. 23 | * 24 | * @internal 25 | */ 26 | final class FileReader 27 | { 28 | /** 29 | * @var null|string 30 | */ 31 | private $stdinContent; 32 | 33 | public static function createSingleton(): self 34 | { 35 | static $instance = null; 36 | 37 | if (!$instance) { 38 | $instance = new self(); 39 | } 40 | 41 | return $instance; 42 | } 43 | 44 | public function read(string $filePath): string 45 | { 46 | if ('php://stdin' === $filePath) { 47 | if (null === $this->stdinContent) { 48 | $this->stdinContent = $this->readRaw($filePath); 49 | } 50 | 51 | return $this->stdinContent; 52 | } 53 | 54 | return $this->readRaw($filePath); 55 | } 56 | 57 | private function readRaw(string $realPath): string 58 | { 59 | $content = @file_get_contents($realPath); 60 | 61 | if (false === $content) { 62 | $error = error_get_last(); 63 | 64 | throw new \RuntimeException(sprintf( 65 | 'Failed to read content from "%s".%s', 66 | $realPath, 67 | null !== $error ? ' '.$error['message'] : '' 68 | )); 69 | } 70 | 71 | return $content; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Finder.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | use Symfony\Component\Finder\Finder as BaseFinder; 18 | 19 | /** 20 | * @author Fabien Potencier 21 | * @author Dariusz Rumiński 22 | */ 23 | class Finder extends BaseFinder 24 | { 25 | public function __construct() 26 | { 27 | parent::__construct(); 28 | 29 | $this 30 | ->files() 31 | ->name('/\.php$/') 32 | ->exclude('vendor') 33 | ; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Fixer/Alias/NoAliasLanguageConstructCallFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\Alias; 16 | 17 | use PhpCsFixer\AbstractFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | use PhpCsFixer\Tokenizer\Token; 22 | use PhpCsFixer\Tokenizer\Tokens; 23 | 24 | final class NoAliasLanguageConstructCallFixer extends AbstractFixer 25 | { 26 | public function getDefinition(): FixerDefinitionInterface 27 | { 28 | return new FixerDefinition( 29 | 'Master language constructs shall be used instead of aliases.', 30 | [ 31 | new CodeSample( 32 | 'isTokenKindFound(T_EXIT); 43 | } 44 | 45 | protected function applyFix(\SplFileInfo $file, Tokens $tokens): void 46 | { 47 | foreach ($tokens as $index => $token) { 48 | if (!$token->isGivenKind(T_EXIT)) { 49 | continue; 50 | } 51 | 52 | if ('exit' === strtolower($token->getContent())) { 53 | continue; 54 | } 55 | 56 | $tokens[$index] = new Token([T_EXIT, 'exit']); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\ArrayNotation; 16 | 17 | use PhpCsFixer\AbstractProxyFixer; 18 | use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; 19 | use PhpCsFixer\Fixer\DeprecatedFixerInterface; 20 | use PhpCsFixer\FixerDefinition\CodeSample; 21 | use PhpCsFixer\FixerDefinition\FixerDefinition; 22 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 23 | 24 | /** 25 | * @deprecated 26 | * 27 | * @author Dariusz Rumiński 28 | * @author Sebastiaan Stok 29 | */ 30 | final class NoTrailingCommaInSinglelineArrayFixer extends AbstractProxyFixer implements DeprecatedFixerInterface 31 | { 32 | public function getDefinition(): FixerDefinitionInterface 33 | { 34 | return new FixerDefinition( 35 | 'PHP single-line arrays should not have trailing comma.', 36 | [new CodeSample("proxyFixers); 43 | } 44 | 45 | protected function createProxyFixers(): array 46 | { 47 | $fixer = new NoTrailingCommaInSinglelineFixer(); 48 | $fixer->configure(['elements' => ['array']]); 49 | 50 | return [$fixer]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Fixer/ArrayNotation/NormalizeIndexBraceFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\ArrayNotation; 16 | 17 | use PhpCsFixer\AbstractFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | use PhpCsFixer\Tokenizer\CT; 22 | use PhpCsFixer\Tokenizer\Token; 23 | use PhpCsFixer\Tokenizer\Tokens; 24 | 25 | /** 26 | * @author Dariusz Rumiński 27 | */ 28 | final class NormalizeIndexBraceFixer extends AbstractFixer 29 | { 30 | public function getDefinition(): FixerDefinitionInterface 31 | { 32 | return new FixerDefinition( 33 | 'Array index should always be written by using square braces.', 34 | [new CodeSample("isTokenKindFound(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN); 41 | } 42 | 43 | protected function applyFix(\SplFileInfo $file, Tokens $tokens): void 44 | { 45 | foreach ($tokens as $index => $token) { 46 | if ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN)) { 47 | $tokens[$index] = new Token('['); 48 | } elseif ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE)) { 49 | $tokens[$index] = new Token(']'); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Fixer/Casing/IntegerLiteralCaseFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\Casing; 16 | 17 | use PhpCsFixer\AbstractFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | use PhpCsFixer\Preg; 22 | use PhpCsFixer\Tokenizer\Token; 23 | use PhpCsFixer\Tokenizer\Tokens; 24 | 25 | final class IntegerLiteralCaseFixer extends AbstractFixer 26 | { 27 | public function getDefinition(): FixerDefinitionInterface 28 | { 29 | return new FixerDefinition( 30 | 'Integer literals must be in correct case.', 31 | [ 32 | new CodeSample( 33 | "isTokenKindFound(T_LNUMBER); 42 | } 43 | 44 | protected function applyFix(\SplFileInfo $file, Tokens $tokens): void 45 | { 46 | foreach ($tokens as $index => $token) { 47 | if (!$token->isGivenKind(T_LNUMBER)) { 48 | continue; 49 | } 50 | 51 | $content = $token->getContent(); 52 | 53 | $newContent = Preg::replaceCallback('#^0([boxBOX])([0-9a-fA-F_]+)$#', static fn ($matches) => '0'.strtolower($matches[1]).strtoupper($matches[2]), $content); 54 | 55 | if ($content === $newContent) { 56 | continue; 57 | } 58 | 59 | $tokens[$index] = new Token([T_LNUMBER, $newContent]); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Fixer/CastNotation/LowercaseCastFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\CastNotation; 16 | 17 | use PhpCsFixer\AbstractFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | use PhpCsFixer\Tokenizer\Token; 22 | use PhpCsFixer\Tokenizer\Tokens; 23 | 24 | final class LowercaseCastFixer extends AbstractFixer 25 | { 26 | public function getDefinition(): FixerDefinitionInterface 27 | { 28 | return new FixerDefinition( 29 | 'Cast should be written in lower case.', 30 | [ 31 | new CodeSample( 32 | 'isAnyTokenKindsFound(Token::getCastTokenKinds()); 54 | } 55 | 56 | protected function applyFix(\SplFileInfo $file, Tokens $tokens): void 57 | { 58 | for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) { 59 | if (!$tokens[$index]->isCast()) { 60 | continue; 61 | } 62 | 63 | $tokens[$index] = new Token([$tokens[$index]->getId(), strtolower($tokens[$index]->getContent())]); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Fixer/ConfigurableFixerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer; 16 | 17 | use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; 18 | use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; 19 | 20 | /** 21 | * @author Dariusz Rumiński 22 | */ 23 | interface ConfigurableFixerInterface extends FixerInterface 24 | { 25 | /** 26 | * Set configuration. 27 | * 28 | * New configuration must override current one, not patch it. 29 | * Using empty array makes fixer to use default configuration 30 | * (or reset configuration from previously configured back to default one). 31 | * 32 | * Some fixers may have no configuration, then - simply don't implement this interface. 33 | * Other ones may have configuration that will change behavior of fixer, 34 | * eg `php_unit_strict` fixer allows to configure which methods should be fixed. 35 | * Finally, some fixers need configuration to work, eg `header_comment`. 36 | * 37 | * @param array $configuration configuration depends on Fixer 38 | * 39 | * @throws InvalidFixerConfigurationException 40 | */ 41 | public function configure(array $configuration): void; 42 | 43 | /** 44 | * Defines the available configuration options of the fixer. 45 | */ 46 | public function getConfigurationDefinition(): FixerConfigurationResolverInterface; 47 | } 48 | -------------------------------------------------------------------------------- /src/Fixer/ControlStructure/NoTrailingCommaInListCallFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\ControlStructure; 16 | 17 | use PhpCsFixer\AbstractProxyFixer; 18 | use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; 19 | use PhpCsFixer\Fixer\DeprecatedFixerInterface; 20 | use PhpCsFixer\FixerDefinition\CodeSample; 21 | use PhpCsFixer\FixerDefinition\FixerDefinition; 22 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 23 | 24 | /** 25 | * @deprecated 26 | * 27 | * @author Dariusz Rumiński 28 | */ 29 | final class NoTrailingCommaInListCallFixer extends AbstractProxyFixer implements DeprecatedFixerInterface 30 | { 31 | public function getDefinition(): FixerDefinitionInterface 32 | { 33 | return new FixerDefinition( 34 | 'Remove trailing commas in list function calls.', 35 | [new CodeSample("proxyFixers); 42 | } 43 | 44 | protected function createProxyFixers(): array 45 | { 46 | $fixer = new NoTrailingCommaInSinglelineFixer(); 47 | $fixer->configure(['elements' => ['array_destructuring']]); 48 | 49 | return [$fixer]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Fixer/DeprecatedFixerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer; 16 | 17 | /** 18 | * @author Kuba Werłos 19 | */ 20 | interface DeprecatedFixerInterface extends FixerInterface 21 | { 22 | /** 23 | * Returns names of fixers to use instead, if any. 24 | * 25 | * @return list 26 | */ 27 | public function getSuccessorsNames(): array; 28 | } 29 | -------------------------------------------------------------------------------- /src/Fixer/ExperimentalFixerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer; 16 | 17 | /** 18 | * @internal 19 | */ 20 | interface ExperimentalFixerInterface extends FixerInterface {} 21 | -------------------------------------------------------------------------------- /src/Fixer/FunctionNotation/FunctionTypehintSpaceFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\FunctionNotation; 16 | 17 | use PhpCsFixer\AbstractProxyFixer; 18 | use PhpCsFixer\Fixer\DeprecatedFixerInterface; 19 | use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer; 20 | use PhpCsFixer\FixerDefinition\CodeSample; 21 | use PhpCsFixer\FixerDefinition\FixerDefinition; 22 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 23 | use PhpCsFixer\Tokenizer\Tokens; 24 | 25 | /** 26 | * @author Dariusz Rumiński 27 | * 28 | * @deprecated 29 | */ 30 | final class FunctionTypehintSpaceFixer extends AbstractProxyFixer implements DeprecatedFixerInterface 31 | { 32 | public function getDefinition(): FixerDefinitionInterface 33 | { 34 | return new FixerDefinition( 35 | 'Ensure single space between function\'s argument and its typehint.', 36 | [ 37 | new CodeSample("isAnyTokenKindsFound([T_FUNCTION, T_FN]); 46 | } 47 | 48 | public function getSuccessorsNames(): array 49 | { 50 | return array_keys($this->proxyFixers); 51 | } 52 | 53 | protected function createProxyFixers(): array 54 | { 55 | $fixer = new TypeDeclarationSpacesFixer(); 56 | $fixer->configure(['elements' => ['function']]); 57 | 58 | return [$fixer]; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\FunctionNotation; 16 | 17 | use PhpCsFixer\AbstractProxyFixer; 18 | use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; 19 | use PhpCsFixer\Fixer\DeprecatedFixerInterface; 20 | use PhpCsFixer\FixerDefinition\CodeSample; 21 | use PhpCsFixer\FixerDefinition\FixerDefinition; 22 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 23 | 24 | /** 25 | * @deprecated 26 | */ 27 | final class NoTrailingCommaInSinglelineFunctionCallFixer extends AbstractProxyFixer implements DeprecatedFixerInterface 28 | { 29 | public function getDefinition(): FixerDefinitionInterface 30 | { 31 | return new FixerDefinition( 32 | 'When making a method or function call on a single line there MUST NOT be a trailing comma after the last argument.', 33 | [new CodeSample("proxyFixers); 50 | } 51 | 52 | protected function createProxyFixers(): array 53 | { 54 | $fixer = new NoTrailingCommaInSinglelineFixer(); 55 | $fixer->configure(['elements' => ['arguments', 'array_destructuring']]); 56 | 57 | return [$fixer]; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Fixer/LanguageConstruct/DeclareParenthesesFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\LanguageConstruct; 16 | 17 | use PhpCsFixer\AbstractFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | use PhpCsFixer\Tokenizer\Tokens; 22 | 23 | final class DeclareParenthesesFixer extends AbstractFixer 24 | { 25 | public function getDefinition(): FixerDefinitionInterface 26 | { 27 | return new FixerDefinition( 28 | 'There must not be spaces around `declare` statement parentheses.', 29 | [new CodeSample("isTokenKindFound(T_DECLARE); 36 | } 37 | 38 | protected function applyFix(\SplFileInfo $file, Tokens $tokens): void 39 | { 40 | for ($index = $tokens->count() - 1; 0 <= $index; --$index) { 41 | $token = $tokens[$index]; 42 | 43 | if (!$token->isGivenKind(T_DECLARE)) { 44 | continue; 45 | } 46 | 47 | $tokens->removeTrailingWhitespace($index); 48 | 49 | $startParenthesisIndex = $tokens->getNextTokenOfKind($index, ['(']); 50 | $tokens->removeTrailingWhitespace($startParenthesisIndex); 51 | 52 | $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex); 53 | $tokens->removeLeadingWhitespace($endParenthesisIndex); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\Operator; 16 | 17 | use PhpCsFixer\AbstractFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | use PhpCsFixer\Tokenizer\Tokens; 22 | 23 | /** 24 | * @author Javier Spagnoletti 25 | */ 26 | final class NotOperatorWithSuccessorSpaceFixer extends AbstractFixer 27 | { 28 | public function getDefinition(): FixerDefinitionInterface 29 | { 30 | return new FixerDefinition( 31 | 'Logical NOT operators (`!`) should have one trailing whitespace.', 32 | [new CodeSample( 33 | 'isTokenKindFound('!'); 56 | } 57 | 58 | protected function applyFix(\SplFileInfo $file, Tokens $tokens): void 59 | { 60 | for ($index = $tokens->count() - 1; $index >= 0; --$index) { 61 | $token = $tokens[$index]; 62 | 63 | if ($token->equals('!')) { 64 | $tokens->ensureWhitespaceAtIndex($index + 1, 0, ' '); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Fixer/Operator/StandardizeNotEqualsFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\Operator; 16 | 17 | use PhpCsFixer\AbstractFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | use PhpCsFixer\Tokenizer\Token; 22 | use PhpCsFixer\Tokenizer\Tokens; 23 | 24 | /** 25 | * @author Dariusz Rumiński 26 | */ 27 | final class StandardizeNotEqualsFixer extends AbstractFixer 28 | { 29 | public function getDefinition(): FixerDefinitionInterface 30 | { 31 | return new FixerDefinition( 32 | 'Replace all `<>` with `!=`.', 33 | [new CodeSample(" \$c;\n")] 34 | ); 35 | } 36 | 37 | /** 38 | * {@inheritdoc} 39 | * 40 | * Must run before BinaryOperatorSpacesFixer. 41 | */ 42 | public function getPriority(): int 43 | { 44 | return 0; 45 | } 46 | 47 | public function isCandidate(Tokens $tokens): bool 48 | { 49 | return $tokens->isTokenKindFound(T_IS_NOT_EQUAL); 50 | } 51 | 52 | protected function applyFix(\SplFileInfo $file, Tokens $tokens): void 53 | { 54 | foreach ($tokens as $index => $token) { 55 | if ($token->isGivenKind(T_IS_NOT_EQUAL)) { 56 | $tokens[$index] = new Token([T_IS_NOT_EQUAL, '!=']); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Fixer/PhpUnit/PhpUnitTargetVersion.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\PhpUnit; 16 | 17 | use Composer\Semver\Comparator; 18 | 19 | /** 20 | * @author Dariusz Rumiński 21 | * 22 | * @internal 23 | */ 24 | final class PhpUnitTargetVersion 25 | { 26 | public const VERSION_3_0 = '3.0'; 27 | public const VERSION_3_2 = '3.2'; 28 | public const VERSION_3_5 = '3.5'; 29 | public const VERSION_4_3 = '4.3'; 30 | public const VERSION_4_8 = '4.8'; 31 | public const VERSION_5_0 = '5.0'; 32 | public const VERSION_5_2 = '5.2'; 33 | public const VERSION_5_4 = '5.4'; 34 | public const VERSION_5_5 = '5.5'; 35 | public const VERSION_5_6 = '5.6'; 36 | public const VERSION_5_7 = '5.7'; 37 | public const VERSION_6_0 = '6.0'; 38 | public const VERSION_7_5 = '7.5'; 39 | public const VERSION_8_4 = '8.4'; 40 | public const VERSION_NEWEST = 'newest'; 41 | 42 | private function __construct() {} 43 | 44 | public static function fulfills(string $candidate, string $target): bool 45 | { 46 | if (self::VERSION_NEWEST === $target) { 47 | throw new \LogicException(sprintf('Parameter `target` shall not be provided as "%s", determine proper target for tested PHPUnit feature instead.', self::VERSION_NEWEST)); 48 | } 49 | 50 | if (self::VERSION_NEWEST === $candidate) { 51 | return true; 52 | } 53 | 54 | return Comparator::greaterThanOrEqualTo($candidate, $target); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Fixer/Phpdoc/PhpdocNoAccessFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\Phpdoc; 16 | 17 | use PhpCsFixer\AbstractProxyFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | 22 | /** 23 | * @author Graham Campbell 24 | * @author Dariusz Rumiński 25 | */ 26 | final class PhpdocNoAccessFixer extends AbstractProxyFixer 27 | { 28 | public function getDefinition(): FixerDefinitionInterface 29 | { 30 | return new FixerDefinition( 31 | '`@access` annotations should be omitted from PHPDoc.', 32 | [ 33 | new CodeSample( 34 | 'configure(['annotations' => ['access']]); 64 | 65 | return [$fixer]; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Fixer/Phpdoc/PhpdocNoPackageFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\Phpdoc; 16 | 17 | use PhpCsFixer\AbstractProxyFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | 22 | /** 23 | * @author Graham Campbell 24 | * @author Dariusz Rumiński 25 | */ 26 | final class PhpdocNoPackageFixer extends AbstractProxyFixer 27 | { 28 | public function getDefinition(): FixerDefinitionInterface 29 | { 30 | return new FixerDefinition( 31 | '`@package` and `@subpackage` annotations should be omitted from PHPDoc.', 32 | [ 33 | new CodeSample( 34 | 'configure(['annotations' => ['package', 'subpackage']]); 64 | 65 | return [$fixer]; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\Semicolon; 16 | 17 | use PhpCsFixer\AbstractFixer; 18 | use PhpCsFixer\FixerDefinition\CodeSample; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | use PhpCsFixer\Tokenizer\Token; 22 | use PhpCsFixer\Tokenizer\Tokens; 23 | 24 | final class SemicolonAfterInstructionFixer extends AbstractFixer 25 | { 26 | public function getDefinition(): FixerDefinitionInterface 27 | { 28 | return new FixerDefinition( 29 | 'Instructions must be terminated with a semicolon.', 30 | [new CodeSample("\n")] 31 | ); 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | * 37 | * Must run before SimplifiedIfReturnFixer. 38 | */ 39 | public function getPriority(): int 40 | { 41 | return 2; 42 | } 43 | 44 | public function isCandidate(Tokens $tokens): bool 45 | { 46 | return $tokens->isTokenKindFound(T_CLOSE_TAG); 47 | } 48 | 49 | protected function applyFix(\SplFileInfo $file, Tokens $tokens): void 50 | { 51 | for ($index = \count($tokens) - 1; $index > 1; --$index) { 52 | if (!$tokens[$index]->isGivenKind(T_CLOSE_TAG)) { 53 | continue; 54 | } 55 | 56 | $prev = $tokens->getPrevMeaningfulToken($index); 57 | if ($tokens[$prev]->equalsAny([';', '{', '}', ':', [T_OPEN_TAG]])) { 58 | continue; 59 | } 60 | 61 | $tokens->insertAt($prev + 1, new Token(';')); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Fixer/Whitespace/CompactNullableTypehintFixer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer\Whitespace; 16 | 17 | use PhpCsFixer\AbstractProxyFixer; 18 | use PhpCsFixer\Fixer\DeprecatedFixerInterface; 19 | use PhpCsFixer\FixerDefinition\FixerDefinition; 20 | use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; 21 | 22 | /** 23 | * @author Jack Cherng 24 | * 25 | * @deprecated 26 | */ 27 | final class CompactNullableTypehintFixer extends AbstractProxyFixer implements DeprecatedFixerInterface 28 | { 29 | private CompactNullableTypeDeclarationFixer $compactNullableTypeDeclarationFixer; 30 | 31 | public function __construct() 32 | { 33 | $this->compactNullableTypeDeclarationFixer = new CompactNullableTypeDeclarationFixer(); 34 | 35 | parent::__construct(); 36 | } 37 | 38 | public function getDefinition(): FixerDefinitionInterface 39 | { 40 | $fixerDefinition = $this->compactNullableTypeDeclarationFixer->getDefinition(); 41 | 42 | return new FixerDefinition( 43 | 'Remove extra spaces in a nullable typehint.', 44 | $fixerDefinition->getCodeSamples(), 45 | $fixerDefinition->getDescription(), 46 | $fixerDefinition->getRiskyDescription(), 47 | ); 48 | } 49 | 50 | public function getSuccessorsNames(): array 51 | { 52 | return [ 53 | $this->compactNullableTypeDeclarationFixer->getName(), 54 | ]; 55 | } 56 | 57 | protected function createProxyFixers(): array 58 | { 59 | return [ 60 | $this->compactNullableTypeDeclarationFixer, 61 | ]; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Fixer/WhitespacesAwareFixerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Fixer; 16 | 17 | use PhpCsFixer\WhitespacesFixerConfig; 18 | 19 | /** 20 | * @author Dariusz Rumiński 21 | */ 22 | interface WhitespacesAwareFixerInterface extends FixerInterface 23 | { 24 | public function setWhitespacesConfig(WhitespacesFixerConfig $config): void; 25 | } 26 | -------------------------------------------------------------------------------- /src/FixerConfiguration/AliasedFixerOption.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerConfiguration; 16 | 17 | /** 18 | * @author ntzm 19 | * 20 | * @internal 21 | */ 22 | final class AliasedFixerOption implements FixerOptionInterface 23 | { 24 | private FixerOptionInterface $fixerOption; 25 | 26 | private string $alias; 27 | 28 | public function __construct(FixerOptionInterface $fixerOption, string $alias) 29 | { 30 | $this->fixerOption = $fixerOption; 31 | $this->alias = $alias; 32 | } 33 | 34 | public function getAlias(): string 35 | { 36 | return $this->alias; 37 | } 38 | 39 | public function getName(): string 40 | { 41 | return $this->fixerOption->getName(); 42 | } 43 | 44 | public function getDescription(): string 45 | { 46 | return $this->fixerOption->getDescription(); 47 | } 48 | 49 | public function hasDefault(): bool 50 | { 51 | return $this->fixerOption->hasDefault(); 52 | } 53 | 54 | public function getDefault() 55 | { 56 | return $this->fixerOption->getDefault(); 57 | } 58 | 59 | public function getAllowedTypes(): ?array 60 | { 61 | return $this->fixerOption->getAllowedTypes(); 62 | } 63 | 64 | public function getAllowedValues(): ?array 65 | { 66 | return $this->fixerOption->getAllowedValues(); 67 | } 68 | 69 | public function getNormalizer(): ?\Closure 70 | { 71 | return $this->fixerOption->getNormalizer(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/FixerConfiguration/AllowedValueSubset.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerConfiguration; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class AllowedValueSubset 21 | { 22 | /** 23 | * @var list 24 | */ 25 | private array $allowedValues; 26 | 27 | /** 28 | * @param list $allowedValues 29 | */ 30 | public function __construct(array $allowedValues) 31 | { 32 | $this->allowedValues = $allowedValues; 33 | sort($this->allowedValues, SORT_FLAG_CASE | SORT_STRING); 34 | } 35 | 36 | /** 37 | * Checks whether the given values are a subset of the allowed ones. 38 | * 39 | * @param mixed $values the value to validate 40 | */ 41 | public function __invoke($values): bool 42 | { 43 | if (!\is_array($values)) { 44 | return false; 45 | } 46 | 47 | foreach ($values as $value) { 48 | if (!\in_array($value, $this->allowedValues, true)) { 49 | return false; 50 | } 51 | } 52 | 53 | return true; 54 | } 55 | 56 | /** 57 | * @return list 58 | */ 59 | public function getAllowedValues(): array 60 | { 61 | return $this->allowedValues; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/FixerConfiguration/DeprecatedFixerOption.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerConfiguration; 16 | 17 | final class DeprecatedFixerOption implements DeprecatedFixerOptionInterface 18 | { 19 | private FixerOptionInterface $option; 20 | 21 | private string $deprecationMessage; 22 | 23 | public function __construct(FixerOptionInterface $option, string $deprecationMessage) 24 | { 25 | $this->option = $option; 26 | $this->deprecationMessage = $deprecationMessage; 27 | } 28 | 29 | public function getName(): string 30 | { 31 | return $this->option->getName(); 32 | } 33 | 34 | public function getDescription(): string 35 | { 36 | return $this->option->getDescription(); 37 | } 38 | 39 | public function hasDefault(): bool 40 | { 41 | return $this->option->hasDefault(); 42 | } 43 | 44 | public function getDefault() 45 | { 46 | return $this->option->getDefault(); 47 | } 48 | 49 | public function getAllowedTypes(): ?array 50 | { 51 | return $this->option->getAllowedTypes(); 52 | } 53 | 54 | public function getAllowedValues(): ?array 55 | { 56 | return $this->option->getAllowedValues(); 57 | } 58 | 59 | public function getNormalizer(): ?\Closure 60 | { 61 | return $this->option->getNormalizer(); 62 | } 63 | 64 | public function getDeprecationMessage(): string 65 | { 66 | return $this->deprecationMessage; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/FixerConfiguration/DeprecatedFixerOptionInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerConfiguration; 16 | 17 | interface DeprecatedFixerOptionInterface extends FixerOptionInterface 18 | { 19 | public function getDeprecationMessage(): string; 20 | } 21 | -------------------------------------------------------------------------------- /src/FixerConfiguration/FixerConfigurationResolverInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerConfiguration; 16 | 17 | interface FixerConfigurationResolverInterface 18 | { 19 | /** 20 | * @return list 21 | */ 22 | public function getOptions(): array; 23 | 24 | /** 25 | * @param array $configuration 26 | * 27 | * @return array 28 | */ 29 | public function resolve(array $configuration): array; 30 | } 31 | -------------------------------------------------------------------------------- /src/FixerConfiguration/FixerOptionInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerConfiguration; 16 | 17 | interface FixerOptionInterface 18 | { 19 | public function getName(): string; 20 | 21 | public function getDescription(): string; 22 | 23 | public function hasDefault(): bool; 24 | 25 | /** 26 | * @return mixed 27 | * 28 | * @throws \LogicException when no default value is defined 29 | */ 30 | public function getDefault(); 31 | 32 | /** 33 | * @return null|list 34 | */ 35 | public function getAllowedTypes(): ?array; 36 | 37 | /** 38 | * @return null|list 39 | */ 40 | public function getAllowedValues(): ?array; 41 | 42 | public function getNormalizer(): ?\Closure; 43 | } 44 | -------------------------------------------------------------------------------- /src/FixerConfiguration/FixerOptionSorter.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerConfiguration; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class FixerOptionSorter 21 | { 22 | /** 23 | * @param iterable $options 24 | * 25 | * @return list 26 | */ 27 | public function sort(iterable $options): array 28 | { 29 | if (!\is_array($options)) { 30 | $options = iterator_to_array($options, false); 31 | } 32 | 33 | usort($options, static fn (FixerOptionInterface $a, FixerOptionInterface $b): int => $a->getName() <=> $b->getName()); 34 | 35 | return $options; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/FixerConfiguration/InvalidOptionsForEnvException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerConfiguration; 16 | 17 | use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; 18 | 19 | /** 20 | * @author Dariusz Rumiński 21 | * 22 | * @internal 23 | */ 24 | final class InvalidOptionsForEnvException extends InvalidOptionsException {} 25 | -------------------------------------------------------------------------------- /src/FixerDefinition/CodeSample.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerDefinition; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | */ 20 | final class CodeSample implements CodeSampleInterface 21 | { 22 | private string $code; 23 | 24 | /** 25 | * @var null|array 26 | */ 27 | private ?array $configuration; 28 | 29 | /** 30 | * @param null|array $configuration 31 | */ 32 | public function __construct(string $code, ?array $configuration = null) 33 | { 34 | $this->code = $code; 35 | $this->configuration = $configuration; 36 | } 37 | 38 | public function getCode(): string 39 | { 40 | return $this->code; 41 | } 42 | 43 | public function getConfiguration(): ?array 44 | { 45 | return $this->configuration; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/FixerDefinition/CodeSampleInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerDefinition; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | */ 20 | interface CodeSampleInterface 21 | { 22 | public function getCode(): string; 23 | 24 | /** 25 | * @return null|array 26 | */ 27 | public function getConfiguration(): ?array; 28 | } 29 | -------------------------------------------------------------------------------- /src/FixerDefinition/FileSpecificCodeSample.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerDefinition; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class FileSpecificCodeSample implements FileSpecificCodeSampleInterface 23 | { 24 | private CodeSampleInterface $codeSample; 25 | 26 | private \SplFileInfo $splFileInfo; 27 | 28 | /** 29 | * @param null|array $configuration 30 | */ 31 | public function __construct( 32 | string $code, 33 | \SplFileInfo $splFileInfo, 34 | ?array $configuration = null 35 | ) { 36 | $this->codeSample = new CodeSample($code, $configuration); 37 | $this->splFileInfo = $splFileInfo; 38 | } 39 | 40 | public function getCode(): string 41 | { 42 | return $this->codeSample->getCode(); 43 | } 44 | 45 | public function getConfiguration(): ?array 46 | { 47 | return $this->codeSample->getConfiguration(); 48 | } 49 | 50 | public function getSplFileInfo(): \SplFileInfo 51 | { 52 | return $this->splFileInfo; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/FixerDefinition/FileSpecificCodeSampleInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerDefinition; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | interface FileSpecificCodeSampleInterface extends CodeSampleInterface 23 | { 24 | public function getSplFileInfo(): \SplFileInfo; 25 | } 26 | -------------------------------------------------------------------------------- /src/FixerDefinition/FixerDefinitionInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerDefinition; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | */ 20 | interface FixerDefinitionInterface 21 | { 22 | public function getSummary(): string; 23 | 24 | public function getDescription(): ?string; 25 | 26 | /** 27 | * @return null|string null for non-risky fixer 28 | */ 29 | public function getRiskyDescription(): ?string; 30 | 31 | /** 32 | * Array of samples, where single sample is [code, configuration]. 33 | * 34 | * @return list 35 | */ 36 | public function getCodeSamples(): array; 37 | } 38 | -------------------------------------------------------------------------------- /src/FixerDefinition/VersionSpecificCodeSample.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerDefinition; 16 | 17 | /** 18 | * @author Andreas Möller 19 | */ 20 | final class VersionSpecificCodeSample implements VersionSpecificCodeSampleInterface 21 | { 22 | private CodeSampleInterface $codeSample; 23 | 24 | private VersionSpecificationInterface $versionSpecification; 25 | 26 | /** 27 | * @param null|array $configuration 28 | */ 29 | public function __construct( 30 | string $code, 31 | VersionSpecificationInterface $versionSpecification, 32 | ?array $configuration = null 33 | ) { 34 | $this->codeSample = new CodeSample($code, $configuration); 35 | $this->versionSpecification = $versionSpecification; 36 | } 37 | 38 | public function getCode(): string 39 | { 40 | return $this->codeSample->getCode(); 41 | } 42 | 43 | public function getConfiguration(): ?array 44 | { 45 | return $this->codeSample->getConfiguration(); 46 | } 47 | 48 | public function isSuitableFor(int $version): bool 49 | { 50 | return $this->versionSpecification->isSatisfiedBy($version); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/FixerDefinition/VersionSpecificCodeSampleInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerDefinition; 16 | 17 | /** 18 | * @author Andreas Moeller 19 | */ 20 | interface VersionSpecificCodeSampleInterface extends CodeSampleInterface 21 | { 22 | public function isSuitableFor(int $version): bool; 23 | } 24 | -------------------------------------------------------------------------------- /src/FixerDefinition/VersionSpecificationInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\FixerDefinition; 16 | 17 | /** 18 | * @author Andreas Möller 19 | */ 20 | interface VersionSpecificationInterface 21 | { 22 | public function isSatisfiedBy(int $version): bool; 23 | } 24 | -------------------------------------------------------------------------------- /src/FixerFileProcessedEvent.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | use Symfony\Contracts\EventDispatcher\Event; 18 | 19 | /** 20 | * Event that is fired when file was processed by Fixer. 21 | * 22 | * @author Dariusz Rumiński 23 | * 24 | * @internal 25 | */ 26 | final class FixerFileProcessedEvent extends Event 27 | { 28 | /** 29 | * Event name. 30 | */ 31 | public const NAME = 'fixer.file_processed'; 32 | 33 | public const STATUS_INVALID = 1; 34 | public const STATUS_SKIPPED = 2; 35 | public const STATUS_NO_CHANGES = 3; 36 | public const STATUS_FIXED = 4; 37 | public const STATUS_EXCEPTION = 5; 38 | public const STATUS_LINT = 6; 39 | 40 | private int $status; 41 | 42 | private ?string $fileRelativePath; 43 | private ?string $fileHash; 44 | 45 | public function __construct(int $status, ?string $fileRelativePath = null, ?string $fileHash = null) 46 | { 47 | $this->status = $status; 48 | $this->fileRelativePath = $fileRelativePath; 49 | $this->fileHash = $fileHash; 50 | } 51 | 52 | public function getStatus(): int 53 | { 54 | return $this->status; 55 | } 56 | 57 | public function getFileRelativePath(): ?string 58 | { 59 | return $this->fileRelativePath; 60 | } 61 | 62 | public function getFileHash(): ?string 63 | { 64 | return $this->fileHash; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/FixerNameValidator.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class FixerNameValidator 23 | { 24 | public function isValid(string $name, bool $isCustom): bool 25 | { 26 | if (!$isCustom) { 27 | return Preg::match('/^[a-z][a-z0-9_]*$/', $name); 28 | } 29 | 30 | return Preg::match('/^[A-Z][a-zA-Z0-9]*\/[a-z][a-z0-9_]*$/', $name); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Linter/CachingLinter.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class CachingLinter implements LinterInterface 23 | { 24 | private LinterInterface $sublinter; 25 | 26 | /** 27 | * @var array 28 | */ 29 | private array $cache = []; 30 | 31 | public function __construct(LinterInterface $linter) 32 | { 33 | $this->sublinter = $linter; 34 | } 35 | 36 | public function isAsync(): bool 37 | { 38 | return $this->sublinter->isAsync(); 39 | } 40 | 41 | public function lintFile(string $path): LintingResultInterface 42 | { 43 | $checksum = md5(file_get_contents($path)); 44 | 45 | if (!isset($this->cache[$checksum])) { 46 | $this->cache[$checksum] = $this->sublinter->lintFile($path); 47 | } 48 | 49 | return $this->cache[$checksum]; 50 | } 51 | 52 | public function lintSource(string $source): LintingResultInterface 53 | { 54 | $checksum = md5($source); 55 | 56 | if (!isset($this->cache[$checksum])) { 57 | $this->cache[$checksum] = $this->sublinter->lintSource($source); 58 | } 59 | 60 | return $this->cache[$checksum]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Linter/Linter.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | /** 18 | * Handle PHP code linting process. 19 | * 20 | * @author Dariusz Rumiński 21 | * 22 | * @internal 23 | */ 24 | final class Linter implements LinterInterface 25 | { 26 | private LinterInterface $subLinter; 27 | 28 | public function __construct() 29 | { 30 | $this->subLinter = new TokenizerLinter(); 31 | } 32 | 33 | public function isAsync(): bool 34 | { 35 | return $this->subLinter->isAsync(); 36 | } 37 | 38 | public function lintFile(string $path): LintingResultInterface 39 | { 40 | return $this->subLinter->lintFile($path); 41 | } 42 | 43 | public function lintSource(string $source): LintingResultInterface 44 | { 45 | return $this->subLinter->lintSource($source); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Linter/LinterInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | /** 18 | * Interface for PHP code linting process manager. 19 | * 20 | * @author Dariusz Rumiński 21 | */ 22 | interface LinterInterface 23 | { 24 | public function isAsync(): bool; 25 | 26 | /** 27 | * Lint PHP file. 28 | */ 29 | public function lintFile(string $path): LintingResultInterface; 30 | 31 | /** 32 | * Lint PHP code. 33 | */ 34 | public function lintSource(string $source): LintingResultInterface; 35 | } 36 | -------------------------------------------------------------------------------- /src/Linter/LintingException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @final 21 | * 22 | * @TODO 4.0 make class "final" 23 | */ 24 | class LintingException extends \RuntimeException {} 25 | -------------------------------------------------------------------------------- /src/Linter/LintingResultInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | */ 20 | interface LintingResultInterface 21 | { 22 | /** 23 | * Check if linting process was successful and raise LintingException if not. 24 | */ 25 | public function check(): void; 26 | } 27 | -------------------------------------------------------------------------------- /src/Linter/ProcessLinterProcessBuilder.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | use Symfony\Component\Process\Process; 18 | 19 | /** 20 | * @author Dariusz Rumiński 21 | * 22 | * @internal 23 | */ 24 | final class ProcessLinterProcessBuilder 25 | { 26 | private string $executable; 27 | 28 | /** 29 | * @param string $executable PHP executable 30 | */ 31 | public function __construct(string $executable) 32 | { 33 | $this->executable = $executable; 34 | } 35 | 36 | public function build(string $path): Process 37 | { 38 | return new Process([ 39 | $this->executable, 40 | '-l', 41 | $path, 42 | ]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Linter/TokenizerLinter.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | use PhpCsFixer\FileReader; 18 | use PhpCsFixer\Tokenizer\CodeHasher; 19 | use PhpCsFixer\Tokenizer\Tokens; 20 | 21 | /** 22 | * Handle PHP code linting. 23 | * 24 | * @author Dariusz Rumiński 25 | * 26 | * @internal 27 | */ 28 | final class TokenizerLinter implements LinterInterface 29 | { 30 | public function isAsync(): bool 31 | { 32 | return false; 33 | } 34 | 35 | public function lintFile(string $path): LintingResultInterface 36 | { 37 | return $this->lintSource(FileReader::createSingleton()->read($path)); 38 | } 39 | 40 | public function lintSource(string $source): LintingResultInterface 41 | { 42 | try { 43 | // To lint, we will parse the source into Tokens. 44 | // During that process, it might throw a ParseError or CompileError. 45 | // If it won't, cache of tokenized version of source will be kept, which is great for Runner. 46 | // Yet, first we need to clear already existing cache to not hit it and lint the code indeed. 47 | $codeHash = CodeHasher::calculateCodeHash($source); 48 | Tokens::clearCache($codeHash); 49 | Tokens::fromCode($source); 50 | 51 | return new TokenizerLintingResult(); 52 | } catch (\CompileError|\ParseError $e) { 53 | return new TokenizerLintingResult($e); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Linter/TokenizerLintingResult.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class TokenizerLintingResult implements LintingResultInterface 23 | { 24 | private ?\Error $error; 25 | 26 | public function __construct(?\Error $error = null) 27 | { 28 | $this->error = $error; 29 | } 30 | 31 | public function check(): void 32 | { 33 | if (null !== $this->error) { 34 | throw new LintingException( 35 | sprintf('%s: %s on line %d.', $this->getMessagePrefix(), $this->error->getMessage(), $this->error->getLine()), 36 | $this->error->getCode(), 37 | $this->error 38 | ); 39 | } 40 | } 41 | 42 | private function getMessagePrefix(): string 43 | { 44 | return $this->error instanceof \ParseError ? 'Parse error' : 'Fatal error'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Linter/UnavailableLinterException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Linter; 16 | 17 | /** 18 | * Exception that is thrown when the chosen linter is not available on the environment. 19 | * 20 | * @author Dariusz Rumiński 21 | * 22 | * @final 23 | * 24 | * @TODO 4.0 make class "final" 25 | */ 26 | class UnavailableLinterException extends \RuntimeException {} 27 | -------------------------------------------------------------------------------- /src/ParallelAwareConfigInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | use PhpCsFixer\Runner\Parallel\ParallelConfig; 18 | 19 | /** 20 | * @author Greg Korba 21 | * 22 | * @TODO 4.0 Include parallel runner config in main ConfigInterface 23 | */ 24 | interface ParallelAwareConfigInterface extends ConfigInterface 25 | { 26 | public function getParallelConfig(): ParallelConfig; 27 | 28 | public function setParallelConfig(ParallelConfig $config): ConfigInterface; 29 | } 30 | -------------------------------------------------------------------------------- /src/PharChecker.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class PharChecker implements PharCheckerInterface 21 | { 22 | public function checkFileValidity(string $filename): ?string 23 | { 24 | try { 25 | $phar = new \Phar($filename); 26 | // free the variable to unlock the file 27 | unset($phar); 28 | } catch (\Exception $e) { 29 | if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) { 30 | throw $e; 31 | } 32 | 33 | return 'Failed to create Phar instance. '.$e->getMessage(); 34 | } 35 | 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/PharCheckerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * @internal 19 | */ 20 | interface PharCheckerInterface 21 | { 22 | /** 23 | * @return null|string the invalidity reason if any, null otherwise 24 | */ 25 | public function checkFileValidity(string $filename): ?string; 26 | } 27 | -------------------------------------------------------------------------------- /src/PregException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * Exception that is thrown when PCRE function encounters an error. 19 | * 20 | * @author Kuba Werłos 21 | * 22 | * @internal 23 | */ 24 | final class PregException extends \RuntimeException {} 25 | -------------------------------------------------------------------------------- /src/RuleSet/AbstractMigrationSetDescription.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet; 16 | 17 | use PhpCsFixer\Preg; 18 | 19 | /** 20 | * @internal 21 | */ 22 | abstract class AbstractMigrationSetDescription extends AbstractRuleSetDescription 23 | { 24 | public function getDescription(): string 25 | { 26 | $name = $this->getName(); 27 | 28 | if (Preg::match('#^@PHPUnit(\d+)(\d)Migration.*$#', $name, $matches)) { 29 | return sprintf('Rules to improve tests code for PHPUnit %d.%d compatibility.', $matches[1], $matches[2]); 30 | } 31 | 32 | if (Preg::match('#^@PHP([\d]{2})Migration.*$#', $name, $matches)) { 33 | return sprintf('Rules to improve code for PHP %d.%d compatibility.', $matches[1][0], $matches[1][1]); 34 | } 35 | 36 | throw new \RuntimeException(sprintf('Cannot generate description for "%s" "%s".', static::class, $name)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/RuleSet/AbstractRuleSetDescription.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet; 16 | 17 | /** 18 | * @internal 19 | */ 20 | abstract class AbstractRuleSetDescription implements RuleSetDescriptionInterface 21 | { 22 | public function __construct() {} 23 | 24 | public function getName(): string 25 | { 26 | $name = substr(static::class, 1 + strrpos(static::class, '\\'), -3); 27 | 28 | return '@'.str_replace('Risky', ':risky', $name); 29 | } 30 | 31 | public function isRisky(): bool 32 | { 33 | return str_contains(static::class, 'Risky'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/RuleSet/DeprecatedRuleSetDescriptionInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet; 16 | 17 | /** 18 | * @author Greg Korba 19 | */ 20 | interface DeprecatedRuleSetDescriptionInterface extends RuleSetDescriptionInterface 21 | { 22 | /** 23 | * Returns names of rule sets to use instead, if any. 24 | * 25 | * @return list 26 | */ 27 | public function getSuccessorsNames(): array; 28 | } 29 | -------------------------------------------------------------------------------- /src/RuleSet/RuleSetDescriptionInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet; 16 | 17 | /** 18 | * @internal 19 | */ 20 | interface RuleSetDescriptionInterface 21 | { 22 | public function getDescription(): string; 23 | 24 | public function getName(): string; 25 | 26 | /** 27 | * Get all rules from rules set. 28 | * 29 | * @return array|bool> 30 | */ 31 | public function getRules(): array; 32 | 33 | public function isRisky(): bool; 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/RuleSetInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet; 16 | 17 | /** 18 | * Set of rules to be used by fixer. 19 | * 20 | * Example of set: ["@PSR2" => true, "@PSR1" => false, "strict" => true]. 21 | * 22 | * @author Dariusz Rumiński 23 | */ 24 | interface RuleSetInterface 25 | { 26 | /** 27 | * @param array|bool> $set 28 | */ 29 | public function __construct(array $set = []); 30 | 31 | /** 32 | * Get configuration for given rule. 33 | * 34 | * @return null|array 35 | */ 36 | public function getRuleConfiguration(string $rule): ?array; 37 | 38 | /** 39 | * Get all rules from rules set. 40 | * 41 | * @return array|true> 42 | */ 43 | public function getRules(): array; 44 | 45 | /** 46 | * Check given rule is in rules set. 47 | */ 48 | public function hasRule(string $rule): bool; 49 | } 50 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/DoctrineAnnotationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class DoctrineAnnotationSet extends AbstractRuleSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | 'doctrine_annotation_array_assignment' => [ 28 | 'operator' => ':', 29 | ], 30 | 'doctrine_annotation_braces' => true, 31 | 'doctrine_annotation_indentation' => true, 32 | 'doctrine_annotation_spaces' => [ 33 | 'before_array_assignments_colon' => false, 34 | ], 35 | ]; 36 | } 37 | 38 | public function getDescription(): string 39 | { 40 | return 'Rules covering Doctrine annotations with configuration based on examples found in `Doctrine Annotation documentation `_ and `Symfony documentation `_.'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PERCS1x0RiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | * 22 | * PER Coding Style v1.0. 23 | * 24 | * @see https://github.com/php-fig/per-coding-style/blob/1.0.0/spec.md 25 | */ 26 | final class PERCS1x0RiskySet extends AbstractRuleSetDescription 27 | { 28 | public function getName(): string 29 | { 30 | return '@PER-CS1.0:risky'; 31 | } 32 | 33 | public function getRules(): array 34 | { 35 | return [ 36 | '@PSR12:risky' => true, 37 | ]; 38 | } 39 | 40 | public function getDescription(): string 41 | { 42 | return 'Rules that follow `PER Coding Style 1.0 `_.'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PERCS1x0Set.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | * 22 | * PER Coding Style v1.0. 23 | * 24 | * @see https://github.com/php-fig/per-coding-style/blob/1.0.0/spec.md 25 | */ 26 | final class PERCS1x0Set extends AbstractRuleSetDescription 27 | { 28 | public function getName(): string 29 | { 30 | return '@PER-CS1.0'; 31 | } 32 | 33 | public function getRules(): array 34 | { 35 | return [ 36 | '@PSR12' => true, 37 | ]; 38 | } 39 | 40 | public function getDescription(): string 41 | { 42 | return 'Rules that follow `PER Coding Style 1.0 `_.'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PERCS2x0RiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | * 22 | * PER Coding Style v2.0. 23 | * 24 | * @see https://github.com/php-fig/per-coding-style/blob/2.0.0/spec.md 25 | */ 26 | final class PERCS2x0RiskySet extends AbstractRuleSetDescription 27 | { 28 | public function getName(): string 29 | { 30 | return '@PER-CS2.0:risky'; 31 | } 32 | 33 | public function getRules(): array 34 | { 35 | return [ 36 | '@PER-CS1.0:risky' => true, 37 | ]; 38 | } 39 | 40 | public function getDescription(): string 41 | { 42 | return 'Rules that follow `PER Coding Style 2.0 `_.'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PERCS2x0Set.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | * 22 | * PER Coding Style v2.0. 23 | * 24 | * @see https://github.com/php-fig/per-coding-style/blob/2.0.0/spec.md 25 | */ 26 | final class PERCS2x0Set extends AbstractRuleSetDescription 27 | { 28 | public function getName(): string 29 | { 30 | return '@PER-CS2.0'; 31 | } 32 | 33 | public function getRules(): array 34 | { 35 | $rules = [ 36 | '@PER-CS1.0' => true, 37 | 'array_indentation' => true, 38 | 'cast_spaces' => true, 39 | 'concat_space' => ['spacing' => 'one'], 40 | 'function_declaration' => [ 41 | 'closure_fn_spacing' => 'none', 42 | ], 43 | 'method_argument_space' => true, 44 | 'single_line_empty_body' => true, 45 | 'trailing_comma_in_multiline' => [ 46 | 'after_heredoc' => true, 47 | 'elements' => ['arguments', 'arrays'], 48 | ], 49 | ]; 50 | 51 | if (\PHP_VERSION_ID >= 8_00_00) { 52 | $rules['trailing_comma_in_multiline']['elements'][] = 'match'; 53 | $rules['trailing_comma_in_multiline']['elements'][] = 'parameters'; 54 | } 55 | 56 | return $rules; 57 | } 58 | 59 | public function getDescription(): string 60 | { 61 | return 'Rules that follow `PER Coding Style 2.0 `_.'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PERCSRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PERCSRiskySet extends AbstractRuleSetDescription 23 | { 24 | public function getName(): string 25 | { 26 | return '@PER-CS:risky'; 27 | } 28 | 29 | public function getRules(): array 30 | { 31 | return [ 32 | '@PER-CS2.0:risky' => true, 33 | ]; 34 | } 35 | 36 | public function getDescription(): string 37 | { 38 | return 'Alias for the latest revision of PER-CS risky rules. Use it if you always want to be in sync with newest PER-CS standard.'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PERCSSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PERCSSet extends AbstractRuleSetDescription 23 | { 24 | public function getName(): string 25 | { 26 | return '@PER-CS'; 27 | } 28 | 29 | public function getRules(): array 30 | { 31 | return [ 32 | '@PER-CS2.0' => true, 33 | ]; 34 | } 35 | 36 | public function getDescription(): string 37 | { 38 | return 'Alias for the latest revision of PER-CS rules. Use it if you always want to be in sync with newest PER-CS standard.'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PERRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | use PhpCsFixer\RuleSet\DeprecatedRuleSetDescriptionInterface; 19 | 20 | /** 21 | * @internal 22 | * 23 | * @deprecated use `@PER-CS:risky` instead 24 | * 25 | * @TODO 4.0 remove me 26 | * 27 | * Last updated to PER Coding Style v2.0. 28 | */ 29 | final class PERRiskySet extends AbstractRuleSetDescription implements DeprecatedRuleSetDescriptionInterface 30 | { 31 | public function getName(): string 32 | { 33 | return '@PER:risky'; 34 | } 35 | 36 | public function getRules(): array 37 | { 38 | return [ 39 | '@PER-CS:risky' => true, 40 | ]; 41 | } 42 | 43 | public function getDescription(): string 44 | { 45 | return 'Alias for the newest PER-CS risky rules. It is recommended you use ``@PER-CS2.0:risky`` instead if you want to stick with stable ruleset.'; 46 | } 47 | 48 | public function getSuccessorsNames(): array 49 | { 50 | return ['@PER-CS:risky']; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PERSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | use PhpCsFixer\RuleSet\DeprecatedRuleSetDescriptionInterface; 19 | 20 | /** 21 | * @internal 22 | * 23 | * @deprecated use `@PER-CS` instead 24 | * 25 | * @TODO 4.0 remove me 26 | * 27 | * Last updated to PER Coding Style v2.0. 28 | */ 29 | final class PERSet extends AbstractRuleSetDescription implements DeprecatedRuleSetDescriptionInterface 30 | { 31 | public function getRules(): array 32 | { 33 | return [ 34 | '@PER-CS' => true, 35 | ]; 36 | } 37 | 38 | public function getDescription(): string 39 | { 40 | return 'Alias for the newest PER-CS rules. It is recommended you use ``@PER-CS2.0`` instead if you want to stick with stable ruleset.'; 41 | } 42 | 43 | public function getSuccessorsNames(): array 44 | { 45 | return ['@PER-CS']; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP54MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP54MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | 'array_syntax' => true, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP56MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP56MigrationRiskySet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | 'pow_to_exponentiation' => true, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP70MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP70MigrationRiskySet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP56Migration:risky' => true, 28 | 'combine_nested_dirname' => true, 29 | 'declare_strict_types' => true, 30 | 'non_printable_character' => true, 31 | 'random_api_migration' => [ 32 | 'replacements' => [ 33 | 'mt_rand' => 'random_int', 34 | 'rand' => 'random_int', 35 | ], 36 | ], 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP70MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP70MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP54Migration' => true, 28 | 'ternary_to_null_coalescing' => true, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP71MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP71MigrationRiskySet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP70Migration:risky' => true, 28 | 'void_return' => true, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP71MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP71MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP70Migration' => true, 28 | 'list_syntax' => true, 29 | 'visibility_required' => true, 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP73MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP73MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP71Migration' => true, 28 | 'heredoc_indentation' => true, 29 | 'method_argument_space' => ['after_heredoc' => true], 30 | 'no_whitespace_before_comma_in_array' => ['after_heredoc' => true], 31 | 'trailing_comma_in_multiline' => ['after_heredoc' => true], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP74MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP74MigrationRiskySet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP71Migration:risky' => true, 28 | 'implode_call' => true, 29 | 'no_alias_functions' => true, 30 | 'use_arrow_functions' => true, 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP74MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP74MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP73Migration' => true, 28 | 'assign_null_coalescing_to_coalesce_equal' => true, 29 | 'normalize_index_brace' => true, 30 | 'short_scalar_cast' => true, 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP80MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP80MigrationRiskySet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP74Migration:risky' => true, 28 | 'get_class_to_class_keyword' => true, 29 | 'modernize_strpos' => true, 30 | 'no_alias_functions' => [ 31 | 'sets' => [ 32 | '@all', 33 | ], 34 | ], 35 | 'no_php4_constructor' => true, 36 | 'no_unneeded_final_method' => true, // final private method (not constructor) are no longer allowed >= PHP8.0 37 | 'no_unreachable_default_argument_value' => true, 38 | ]; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP80MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP80MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP74Migration' => true, 28 | 'clean_namespace' => true, 29 | 'no_unset_cast' => true, 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP81MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP81MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP80Migration' => true, 28 | 'octal_notation' => true, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP82MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP82MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP81Migration' => true, 28 | 'simple_to_complex_string_variable' => true, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP83MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP83MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP82Migration' => true, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHP84MigrationSet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHP84MigrationSet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHP83Migration' => true, 28 | 'nullable_type_declaration_for_default_null_value' => true, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit100MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PHPUnit100MigrationRiskySet extends AbstractMigrationSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | '@PHPUnit84Migration:risky' => true, 28 | 'php_unit_data_provider_static' => ['force' => true], 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit30MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit30MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | 'php_unit_dedicate_assert' => [ 29 | 'target' => PhpUnitTargetVersion::VERSION_3_0, 30 | ], 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit32MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit32MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit30Migration:risky' => true, 29 | 'php_unit_no_expectation_annotation' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_3_2, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit35MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit35MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit32Migration:risky' => true, 29 | 'php_unit_dedicate_assert' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_3_5, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit43MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit43MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit35Migration:risky' => true, 29 | 'php_unit_no_expectation_annotation' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_4_3, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit48MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit48MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit43Migration:risky' => true, 29 | 'php_unit_namespaced' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_4_8, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit50MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit50MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit48Migration:risky' => true, 29 | 'php_unit_dedicate_assert' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_5_0, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit52MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit52MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit50Migration:risky' => true, 29 | 'php_unit_expectation' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_5_2, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit54MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit54MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit52Migration:risky' => true, 29 | 'php_unit_mock' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_5_4, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit55MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit55MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit54Migration:risky' => true, 29 | 'php_unit_mock' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_5_5, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit56MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit56MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit55Migration:risky' => true, 29 | 'php_unit_dedicate_assert' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_5_6, 31 | ], 32 | 'php_unit_expectation' => [ 33 | 'target' => PhpUnitTargetVersion::VERSION_5_6, 34 | ], 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit57MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit57MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit56Migration:risky' => true, 29 | 'php_unit_namespaced' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_5_7, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit60MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit60MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit57Migration:risky' => true, 29 | 'php_unit_namespaced' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_6_0, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit75MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit75MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit60Migration:risky' => true, 29 | 'php_unit_dedicate_assert_internal_type' => [ 30 | 'target' => PhpUnitTargetVersion::VERSION_7_5, 31 | ], 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PHPUnit84MigrationRiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; 18 | use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; 19 | 20 | /** 21 | * @internal 22 | */ 23 | final class PHPUnit84MigrationRiskySet extends AbstractMigrationSetDescription 24 | { 25 | public function getRules(): array 26 | { 27 | return [ 28 | '@PHPUnit60Migration:risky' => true, 29 | '@PHPUnit75Migration:risky' => true, 30 | 'php_unit_expectation' => [ 31 | 'target' => PhpUnitTargetVersion::VERSION_8_4, 32 | ], 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PSR12RiskySet.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PSR12RiskySet extends AbstractRuleSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | 'no_trailing_whitespace_in_string' => true, 28 | 'no_unreachable_default_argument_value' => true, 29 | ]; 30 | } 31 | 32 | public function getDescription(): string 33 | { 34 | return 'Rules that follow `PSR-12 `_ standard.'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/RuleSet/Sets/PSR1Set.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\RuleSet\Sets; 16 | 17 | use PhpCsFixer\RuleSet\AbstractRuleSetDescription; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class PSR1Set extends AbstractRuleSetDescription 23 | { 24 | public function getRules(): array 25 | { 26 | return [ 27 | 'encoding' => true, 28 | 'full_opening_tag' => true, 29 | ]; 30 | } 31 | 32 | public function getDescription(): string 33 | { 34 | return 'Rules that follow `PSR-1 `_ standard.'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Runner/LintingFileIterator.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner; 16 | 17 | use PhpCsFixer\Linter\LinterInterface; 18 | use PhpCsFixer\Linter\LintingResultInterface; 19 | 20 | /** 21 | * @author Dariusz Rumiński 22 | * 23 | * @internal 24 | * 25 | * @extends \IteratorIterator> 26 | */ 27 | final class LintingFileIterator extends \IteratorIterator implements LintingResultAwareFileIteratorInterface 28 | { 29 | /** 30 | * @var null|LintingResultInterface 31 | */ 32 | private $currentResult; 33 | 34 | private LinterInterface $linter; 35 | 36 | /** 37 | * @param \Iterator $iterator 38 | */ 39 | public function __construct(\Iterator $iterator, LinterInterface $linter) 40 | { 41 | parent::__construct($iterator); 42 | 43 | $this->linter = $linter; 44 | } 45 | 46 | public function currentLintingResult(): ?LintingResultInterface 47 | { 48 | return $this->currentResult; 49 | } 50 | 51 | public function next(): void 52 | { 53 | parent::next(); 54 | 55 | $this->currentResult = $this->valid() ? $this->handleItem($this->current()) : null; 56 | } 57 | 58 | public function rewind(): void 59 | { 60 | parent::rewind(); 61 | 62 | $this->currentResult = $this->valid() ? $this->handleItem($this->current()) : null; 63 | } 64 | 65 | private function handleItem(\SplFileInfo $file): LintingResultInterface 66 | { 67 | return $this->linter->lintFile($file->getRealPath()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Runner/LintingResultAwareFileIteratorInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner; 16 | 17 | use PhpCsFixer\Linter\LintingResultInterface; 18 | 19 | /** 20 | * @author Greg Korba 21 | * 22 | * @internal 23 | * 24 | * @extends \Iterator 25 | */ 26 | interface LintingResultAwareFileIteratorInterface extends \Iterator 27 | { 28 | public function currentLintingResult(): ?LintingResultInterface; 29 | } 30 | -------------------------------------------------------------------------------- /src/Runner/Parallel/ParallelAction.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner\Parallel; 16 | 17 | /** 18 | * @author Greg Korba 19 | * 20 | * @internal 21 | */ 22 | final class ParallelAction 23 | { 24 | // Actions executed by the runner (main process) 25 | public const RUNNER_REQUEST_ANALYSIS = 'requestAnalysis'; 26 | public const RUNNER_THANK_YOU = 'thankYou'; 27 | 28 | // Actions executed by the worker 29 | public const WORKER_ERROR_REPORT = 'errorReport'; 30 | public const WORKER_GET_FILE_CHUNK = 'getFileChunk'; 31 | public const WORKER_HELLO = 'hello'; 32 | public const WORKER_RESULT = 'result'; 33 | 34 | private function __construct() {} 35 | } 36 | -------------------------------------------------------------------------------- /src/Runner/Parallel/ParallelConfig.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner\Parallel; 16 | 17 | /** 18 | * @author Greg Korba 19 | */ 20 | final class ParallelConfig 21 | { 22 | /** @internal */ 23 | public const DEFAULT_FILES_PER_PROCESS = 10; 24 | 25 | /** @internal */ 26 | public const DEFAULT_PROCESS_TIMEOUT = 120; 27 | 28 | private int $filesPerProcess; 29 | private int $maxProcesses; 30 | private int $processTimeout; 31 | 32 | /** 33 | * @param positive-int $maxProcesses 34 | * @param positive-int $filesPerProcess 35 | * @param positive-int $processTimeout 36 | */ 37 | public function __construct( 38 | int $maxProcesses = 2, 39 | int $filesPerProcess = self::DEFAULT_FILES_PER_PROCESS, 40 | int $processTimeout = self::DEFAULT_PROCESS_TIMEOUT 41 | ) { 42 | if ($maxProcesses <= 0 || $filesPerProcess <= 0 || $processTimeout <= 0) { 43 | throw new \InvalidArgumentException('Invalid parallelisation configuration: only positive integers are allowed'); 44 | } 45 | 46 | $this->maxProcesses = $maxProcesses; 47 | $this->filesPerProcess = $filesPerProcess; 48 | $this->processTimeout = $processTimeout; 49 | } 50 | 51 | public function getFilesPerProcess(): int 52 | { 53 | return $this->filesPerProcess; 54 | } 55 | 56 | public function getMaxProcesses(): int 57 | { 58 | return $this->maxProcesses; 59 | } 60 | 61 | public function getProcessTimeout(): int 62 | { 63 | return $this->processTimeout; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Runner/Parallel/ParallelConfigFactory.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner\Parallel; 16 | 17 | use Fidry\CpuCoreCounter\CpuCoreCounter; 18 | use Fidry\CpuCoreCounter\Finder\DummyCpuCoreFinder; 19 | use Fidry\CpuCoreCounter\Finder\FinderRegistry; 20 | 21 | /** 22 | * @author Dariusz Rumiński 23 | */ 24 | final class ParallelConfigFactory 25 | { 26 | private static ?CpuCoreCounter $cpuDetector = null; 27 | 28 | private function __construct() {} 29 | 30 | public static function sequential(): ParallelConfig 31 | { 32 | return new ParallelConfig(1); 33 | } 34 | 35 | /** 36 | * @param null|positive-int $filesPerProcess 37 | * @param null|positive-int $processTimeout 38 | */ 39 | public static function detect( 40 | ?int $filesPerProcess = null, 41 | ?int $processTimeout = null 42 | ): ParallelConfig { 43 | if (null === self::$cpuDetector) { 44 | self::$cpuDetector = new CpuCoreCounter([ 45 | ...FinderRegistry::getDefaultLogicalFinders(), 46 | new DummyCpuCoreFinder(1), 47 | ]); 48 | } 49 | 50 | return new ParallelConfig( 51 | self::$cpuDetector->getCount(), 52 | $filesPerProcess ?? ParallelConfig::DEFAULT_FILES_PER_PROCESS, 53 | $processTimeout ?? ParallelConfig::DEFAULT_PROCESS_TIMEOUT 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Runner/Parallel/ParallelisationException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner\Parallel; 16 | 17 | /** 18 | * Common exception for all the errors related to parallelisation. 19 | * 20 | * @author Greg Korba 21 | * 22 | * @internal 23 | */ 24 | final class ParallelisationException extends \RuntimeException 25 | { 26 | public static function forUnknownIdentifier(ProcessIdentifier $identifier): self 27 | { 28 | return new self('Unknown process identifier: '.$identifier->toString()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Runner/Parallel/ProcessIdentifier.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner\Parallel; 16 | 17 | /** 18 | * Represents identifier of single process that is handled within parallel run. 19 | * 20 | * @author Greg Korba 21 | * 22 | * @internal 23 | */ 24 | final class ProcessIdentifier 25 | { 26 | private const IDENTIFIER_PREFIX = 'php-cs-fixer_parallel_'; 27 | 28 | private string $identifier; 29 | 30 | private function __construct(string $identifier) 31 | { 32 | $this->identifier = $identifier; 33 | } 34 | 35 | public function toString(): string 36 | { 37 | return $this->identifier; 38 | } 39 | 40 | public static function create(): self 41 | { 42 | return new self(uniqid(self::IDENTIFIER_PREFIX, true)); 43 | } 44 | 45 | public static function fromRaw(string $identifier): self 46 | { 47 | if (!str_starts_with($identifier, self::IDENTIFIER_PREFIX)) { 48 | throw new ParallelisationException(sprintf('Invalid process identifier "%s".', $identifier)); 49 | } 50 | 51 | return new self($identifier); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Runner/Parallel/WorkerException.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner\Parallel; 16 | 17 | use Throwable; 18 | 19 | /** 20 | * @author Greg Korba 21 | * 22 | * @internal 23 | */ 24 | final class WorkerException extends \RuntimeException 25 | { 26 | private string $originalTraceAsString; 27 | 28 | private function __construct(string $message, int $code) 29 | { 30 | parent::__construct($message, $code); 31 | } 32 | 33 | /** 34 | * @param array{ 35 | * class: class-string, 36 | * message: string, 37 | * file: string, 38 | * line: int, 39 | * code: int, 40 | * trace: string 41 | * } $data 42 | */ 43 | public static function fromRaw(array $data): self 44 | { 45 | $exception = new self( 46 | sprintf('[%s] %s', $data['class'], $data['message']), 47 | $data['code'] 48 | ); 49 | $exception->file = $data['file']; 50 | $exception->line = $data['line']; 51 | $exception->originalTraceAsString = sprintf( 52 | '## %s(%d)%s%s', 53 | $data['file'], 54 | $data['line'], 55 | PHP_EOL, 56 | $data['trace'] 57 | ); 58 | 59 | return $exception; 60 | } 61 | 62 | public function getOriginalTraceAsString(): string 63 | { 64 | return $this->originalTraceAsString; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Runner/RunnerConfig.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Runner; 16 | 17 | use PhpCsFixer\Runner\Parallel\ParallelConfig; 18 | 19 | /** 20 | * @author Greg Korba 21 | * 22 | * @internal 23 | */ 24 | final class RunnerConfig 25 | { 26 | private bool $isDryRun; 27 | private bool $stopOnViolation; 28 | private ParallelConfig $parallelConfig; 29 | private ?string $configFile; 30 | 31 | public function __construct( 32 | bool $isDryRun, 33 | bool $stopOnViolation, 34 | ParallelConfig $parallelConfig, 35 | ?string $configFile = null 36 | ) { 37 | $this->isDryRun = $isDryRun; 38 | $this->stopOnViolation = $stopOnViolation; 39 | $this->parallelConfig = $parallelConfig; 40 | $this->configFile = $configFile; 41 | } 42 | 43 | public function isDryRun(): bool 44 | { 45 | return $this->isDryRun; 46 | } 47 | 48 | public function shouldStopOnViolation(): bool 49 | { 50 | return $this->stopOnViolation; 51 | } 52 | 53 | public function getParallelConfig(): ParallelConfig 54 | { 55 | return $this->parallelConfig; 56 | } 57 | 58 | public function getConfigFile(): ?string 59 | { 60 | return $this->configFile; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Tokenizer/AbstractTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer; 16 | 17 | use PhpCsFixer\Utils; 18 | 19 | /** 20 | * @author Dariusz Rumiński 21 | * 22 | * @internal 23 | */ 24 | abstract class AbstractTransformer implements TransformerInterface 25 | { 26 | public function getName(): string 27 | { 28 | $nameParts = explode('\\', static::class); 29 | $name = substr(end($nameParts), 0, -\strlen('Transformer')); 30 | 31 | return Utils::camelCaseToUnderscore($name); 32 | } 33 | 34 | public function getPriority(): int 35 | { 36 | return 0; 37 | } 38 | 39 | abstract public function getCustomTokens(): array; 40 | } 41 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/AbstractControlCaseStructuresAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | /** 18 | * @internal 19 | */ 20 | abstract class AbstractControlCaseStructuresAnalysis 21 | { 22 | private int $index; 23 | 24 | private int $open; 25 | 26 | private int $close; 27 | 28 | public function __construct(int $index, int $open, int $close) 29 | { 30 | $this->index = $index; 31 | $this->open = $open; 32 | $this->close = $close; 33 | } 34 | 35 | public function getIndex(): int 36 | { 37 | return $this->index; 38 | } 39 | 40 | public function getOpenIndex(): int 41 | { 42 | return $this->open; 43 | } 44 | 45 | public function getCloseIndex(): int 46 | { 47 | return $this->close; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/ArgumentAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class ArgumentAnalysis 21 | { 22 | /** 23 | * The name of the argument. 24 | */ 25 | private ?string $name; 26 | 27 | /** 28 | * The index where the name is located in the supplied Tokens object. 29 | */ 30 | private ?int $nameIndex; 31 | 32 | /** 33 | * The default value of the argument. 34 | */ 35 | private ?string $default; 36 | 37 | /** 38 | * The type analysis of the argument. 39 | */ 40 | private ?TypeAnalysis $typeAnalysis; 41 | 42 | public function __construct(?string $name, ?int $nameIndex, ?string $default, ?TypeAnalysis $typeAnalysis = null) 43 | { 44 | $this->name = $name; 45 | $this->nameIndex = $nameIndex; 46 | $this->default = $default ?? null; 47 | $this->typeAnalysis = $typeAnalysis ?? null; 48 | } 49 | 50 | public function getDefault(): ?string 51 | { 52 | return $this->default; 53 | } 54 | 55 | public function hasDefault(): bool 56 | { 57 | return null !== $this->default; 58 | } 59 | 60 | public function getName(): ?string 61 | { 62 | return $this->name; 63 | } 64 | 65 | public function getNameIndex(): ?int 66 | { 67 | return $this->nameIndex; 68 | } 69 | 70 | public function getTypeAnalysis(): ?TypeAnalysis 71 | { 72 | return $this->typeAnalysis; 73 | } 74 | 75 | public function hasTypeAnalysis(): bool 76 | { 77 | return null !== $this->typeAnalysis; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/CaseAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | /** 18 | * @author Kuba Werłos 19 | * 20 | * @internal 21 | */ 22 | final class CaseAnalysis 23 | { 24 | private int $index; 25 | 26 | private int $colonIndex; 27 | 28 | public function __construct(int $index, int $colonIndex) 29 | { 30 | $this->index = $index; 31 | $this->colonIndex = $colonIndex; 32 | } 33 | 34 | public function getIndex(): int 35 | { 36 | return $this->index; 37 | } 38 | 39 | public function getColonIndex(): int 40 | { 41 | return $this->colonIndex; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/DataProviderAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | use PhpCsFixer\Console\Application; 18 | use PhpCsFixer\Utils; 19 | 20 | final class DataProviderAnalysis 21 | { 22 | private string $name; 23 | 24 | private int $nameIndex; 25 | 26 | /** @var list */ 27 | private array $usageIndices; 28 | 29 | /** 30 | * @param list $usageIndices 31 | */ 32 | public function __construct(string $name, int $nameIndex, array $usageIndices) 33 | { 34 | if (!array_is_list($usageIndices)) { 35 | Utils::triggerDeprecation(new \InvalidArgumentException(sprintf( 36 | 'Parameter "usageIndices" should be a list. This will be enforced in version %d.0.', 37 | Application::getMajorVersion() + 1 38 | ))); 39 | } 40 | 41 | $this->name = $name; 42 | $this->nameIndex = $nameIndex; 43 | $this->usageIndices = $usageIndices; 44 | } 45 | 46 | public function getName(): string 47 | { 48 | return $this->name; 49 | } 50 | 51 | public function getNameIndex(): int 52 | { 53 | return $this->nameIndex; 54 | } 55 | 56 | /** 57 | * @return list 58 | */ 59 | public function getUsageIndices(): array 60 | { 61 | return $this->usageIndices; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/DefaultAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class DefaultAnalysis 21 | { 22 | private int $index; 23 | 24 | private int $colonIndex; 25 | 26 | public function __construct(int $index, int $colonIndex) 27 | { 28 | $this->index = $index; 29 | $this->colonIndex = $colonIndex; 30 | } 31 | 32 | public function getIndex(): int 33 | { 34 | return $this->index; 35 | } 36 | 37 | public function getColonIndex(): int 38 | { 39 | return $this->colonIndex; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/EnumAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class EnumAnalysis extends AbstractControlCaseStructuresAnalysis 21 | { 22 | /** 23 | * @var list 24 | */ 25 | private array $cases; 26 | 27 | /** 28 | * @param list $cases 29 | */ 30 | public function __construct(int $index, int $open, int $close, array $cases) 31 | { 32 | parent::__construct($index, $open, $close); 33 | 34 | $this->cases = $cases; 35 | } 36 | 37 | /** 38 | * @return list 39 | */ 40 | public function getCases(): array 41 | { 42 | return $this->cases; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/MatchAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class MatchAnalysis extends AbstractControlCaseStructuresAnalysis 21 | { 22 | private ?DefaultAnalysis $defaultAnalysis; 23 | 24 | public function __construct(int $index, int $open, int $close, ?DefaultAnalysis $defaultAnalysis) 25 | { 26 | parent::__construct($index, $open, $close); 27 | 28 | $this->defaultAnalysis = $defaultAnalysis; 29 | } 30 | 31 | public function getDefaultAnalysis(): ?DefaultAnalysis 32 | { 33 | return $this->defaultAnalysis; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/StartEndTokenAwareAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | interface StartEndTokenAwareAnalysis 18 | { 19 | /** 20 | * The start index of the analyzed subject inside of the Tokens. 21 | */ 22 | public function getStartIndex(): int; 23 | 24 | /** 25 | * The end index of the analyzed subject inside of the Tokens. 26 | */ 27 | public function getEndIndex(): int; 28 | } 29 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/Analysis/SwitchAnalysis.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer\Analysis; 16 | 17 | /** 18 | * @internal 19 | */ 20 | final class SwitchAnalysis extends AbstractControlCaseStructuresAnalysis 21 | { 22 | /** 23 | * @var list 24 | */ 25 | private array $cases; 26 | 27 | private ?DefaultAnalysis $defaultAnalysis; 28 | 29 | /** 30 | * @param list $cases 31 | */ 32 | public function __construct(int $index, int $open, int $close, array $cases, ?DefaultAnalysis $defaultAnalysis) 33 | { 34 | parent::__construct($index, $open, $close); 35 | 36 | $this->cases = $cases; 37 | $this->defaultAnalysis = $defaultAnalysis; 38 | } 39 | 40 | /** 41 | * @return list 42 | */ 43 | public function getCases(): array 44 | { 45 | return $this->cases; 46 | } 47 | 48 | public function getDefaultAnalysis(): ?DefaultAnalysis 49 | { 50 | return $this->defaultAnalysis; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/BlocksAnalyzer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer; 16 | 17 | use PhpCsFixer\Tokenizer\Token; 18 | use PhpCsFixer\Tokenizer\Tokens; 19 | 20 | /** 21 | * @author Kuba Werłos 22 | * 23 | * @internal 24 | */ 25 | final class BlocksAnalyzer 26 | { 27 | public function isBlock(Tokens $tokens, int $openIndex, int $closeIndex): bool 28 | { 29 | if (!$tokens->offsetExists($openIndex)) { 30 | throw new \InvalidArgumentException(sprintf('Tokex index %d for potential block opening does not exist.', $openIndex)); 31 | } 32 | 33 | if (!$tokens->offsetExists($closeIndex)) { 34 | throw new \InvalidArgumentException(sprintf('Token index %d for potential block closure does not exist.', $closeIndex)); 35 | } 36 | 37 | $blockType = $this->getBlockType($tokens[$openIndex]); 38 | 39 | if (null === $blockType) { 40 | return false; 41 | } 42 | 43 | return $closeIndex === $tokens->findBlockEnd($blockType, $openIndex); 44 | } 45 | 46 | /** 47 | * @return Tokens::BLOCK_TYPE_* 48 | */ 49 | private function getBlockType(Token $token): ?int 50 | { 51 | foreach (Tokens::getBlockEdgeDefinitions() as $blockType => $definition) { 52 | if ($token->equals($definition['start'])) { 53 | return $blockType; 54 | } 55 | } 56 | 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/GotoLabelAnalyzer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer; 16 | 17 | use PhpCsFixer\Tokenizer\Tokens; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class GotoLabelAnalyzer 23 | { 24 | public function belongsToGoToLabel(Tokens $tokens, int $index): bool 25 | { 26 | if (!$tokens[$index]->equals(':')) { 27 | return false; 28 | } 29 | 30 | $prevMeaningfulTokenIndex = $tokens->getPrevMeaningfulToken($index); 31 | 32 | if (!$tokens[$prevMeaningfulTokenIndex]->isGivenKind(T_STRING)) { 33 | return false; 34 | } 35 | 36 | $prevMeaningfulTokenIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulTokenIndex); 37 | 38 | return $tokens[$prevMeaningfulTokenIndex]->equalsAny([':', ';', '{', '}', [T_OPEN_TAG]]); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/ReferenceAnalyzer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer; 16 | 17 | use PhpCsFixer\Tokenizer\CT; 18 | use PhpCsFixer\Tokenizer\Tokens; 19 | 20 | /** 21 | * @author Kuba Werłos 22 | * 23 | * @internal 24 | */ 25 | final class ReferenceAnalyzer 26 | { 27 | public function isReference(Tokens $tokens, int $index): bool 28 | { 29 | if ($tokens[$index]->isGivenKind(CT::T_RETURN_REF)) { 30 | return true; 31 | } 32 | 33 | if (!$tokens[$index]->equals('&')) { 34 | return false; 35 | } 36 | 37 | /** @var int $index */ 38 | $index = $tokens->getPrevMeaningfulToken($index); 39 | if ($tokens[$index]->equalsAny(['=', [T_AS], [T_CALLABLE], [T_DOUBLE_ARROW], [CT::T_ARRAY_TYPEHINT]])) { 40 | return true; 41 | } 42 | 43 | if ($tokens[$index]->isGivenKind(T_STRING)) { 44 | $index = $tokens->getPrevMeaningfulToken($index); 45 | } 46 | 47 | return $tokens[$index]->equalsAny(['(', ',', [T_NS_SEPARATOR], [CT::T_NULLABLE_TYPE]]); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Tokenizer/Analyzer/WhitespacesAnalyzer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Analyzer; 16 | 17 | use PhpCsFixer\Tokenizer\Tokens; 18 | 19 | /** 20 | * @internal 21 | */ 22 | final class WhitespacesAnalyzer 23 | { 24 | public static function detectIndent(Tokens $tokens, int $index): string 25 | { 26 | while (true) { 27 | $whitespaceIndex = $tokens->getPrevTokenOfKind($index, [[T_WHITESPACE]]); 28 | 29 | if (null === $whitespaceIndex) { 30 | return ''; 31 | } 32 | 33 | $whitespaceToken = $tokens[$whitespaceIndex]; 34 | 35 | if (str_contains($whitespaceToken->getContent(), "\n")) { 36 | break; 37 | } 38 | 39 | $prevToken = $tokens[$whitespaceIndex - 1]; 40 | 41 | if ($prevToken->isGivenKind([T_OPEN_TAG, T_COMMENT]) && "\n" === substr($prevToken->getContent(), -1)) { 42 | break; 43 | } 44 | 45 | $index = $whitespaceIndex; 46 | } 47 | 48 | $explodedContent = explode("\n", $whitespaceToken->getContent()); 49 | 50 | return end($explodedContent); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Tokenizer/CodeHasher.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class CodeHasher 23 | { 24 | private function __construct() 25 | { 26 | // cannot create instance of util. class 27 | } 28 | 29 | /** 30 | * Calculate hash for code. 31 | * 32 | * @return non-empty-string 33 | */ 34 | public static function calculateCodeHash(string $code): string 35 | { 36 | return md5($code); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/ArrayTypehintTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTransformer; 18 | use PhpCsFixer\Tokenizer\CT; 19 | use PhpCsFixer\Tokenizer\Token; 20 | use PhpCsFixer\Tokenizer\Tokens; 21 | 22 | /** 23 | * Transform `array` typehint from T_ARRAY into CT::T_ARRAY_TYPEHINT. 24 | * 25 | * @author Dariusz Rumiński 26 | * 27 | * @internal 28 | */ 29 | final class ArrayTypehintTransformer extends AbstractTransformer 30 | { 31 | public function getRequiredPhpVersionId(): int 32 | { 33 | return 5_00_00; 34 | } 35 | 36 | public function process(Tokens $tokens, Token $token, int $index): void 37 | { 38 | if (!$token->isGivenKind(T_ARRAY)) { 39 | return; 40 | } 41 | 42 | $nextIndex = $tokens->getNextMeaningfulToken($index); 43 | $nextToken = $tokens[$nextIndex]; 44 | 45 | if (!$nextToken->equals('(')) { 46 | $tokens[$index] = new Token([CT::T_ARRAY_TYPEHINT, $token->getContent()]); 47 | } 48 | } 49 | 50 | public function getCustomTokens(): array 51 | { 52 | return [CT::T_ARRAY_TYPEHINT]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/AttributeTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTransformer; 18 | use PhpCsFixer\Tokenizer\CT; 19 | use PhpCsFixer\Tokenizer\Token; 20 | use PhpCsFixer\Tokenizer\Tokens; 21 | 22 | /** 23 | * Transforms attribute related Tokens. 24 | * 25 | * @internal 26 | */ 27 | final class AttributeTransformer extends AbstractTransformer 28 | { 29 | public function getPriority(): int 30 | { 31 | // must run before all other transformers that might touch attributes 32 | return 200; 33 | } 34 | 35 | public function getRequiredPhpVersionId(): int 36 | { 37 | return 8_00_00; 38 | } 39 | 40 | public function process(Tokens $tokens, Token $token, int $index): void 41 | { 42 | if (!$tokens[$index]->isGivenKind(T_ATTRIBUTE)) { 43 | return; 44 | } 45 | 46 | $level = 1; 47 | 48 | do { 49 | ++$index; 50 | 51 | if ($tokens[$index]->equals('[')) { 52 | ++$level; 53 | } elseif ($tokens[$index]->equals(']')) { 54 | --$level; 55 | } 56 | } while (0 < $level); 57 | 58 | $tokens[$index] = new Token([CT::T_ATTRIBUTE_CLOSE, ']']); 59 | } 60 | 61 | public function getCustomTokens(): array 62 | { 63 | return [ 64 | CT::T_ATTRIBUTE_CLOSE, 65 | ]; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/ClassConstantTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTransformer; 18 | use PhpCsFixer\Tokenizer\CT; 19 | use PhpCsFixer\Tokenizer\Token; 20 | use PhpCsFixer\Tokenizer\Tokens; 21 | 22 | /** 23 | * Transform `class` class' constant from T_CLASS into CT::T_CLASS_CONSTANT. 24 | * 25 | * @author Dariusz Rumiński 26 | * 27 | * @internal 28 | */ 29 | final class ClassConstantTransformer extends AbstractTransformer 30 | { 31 | public function getRequiredPhpVersionId(): int 32 | { 33 | return 5_05_00; 34 | } 35 | 36 | public function process(Tokens $tokens, Token $token, int $index): void 37 | { 38 | if (!$token->equalsAny([ 39 | [T_CLASS, 'class'], 40 | [T_STRING, 'class'], 41 | ], false)) { 42 | return; 43 | } 44 | 45 | $prevIndex = $tokens->getPrevMeaningfulToken($index); 46 | $prevToken = $tokens[$prevIndex]; 47 | 48 | if ($prevToken->isGivenKind(T_DOUBLE_COLON)) { 49 | $tokens[$index] = new Token([CT::T_CLASS_CONSTANT, $token->getContent()]); 50 | } 51 | } 52 | 53 | public function getCustomTokens(): array 54 | { 55 | return [CT::T_CLASS_CONSTANT]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/FirstClassCallableTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTransformer; 18 | use PhpCsFixer\Tokenizer\CT; 19 | use PhpCsFixer\Tokenizer\Token; 20 | use PhpCsFixer\Tokenizer\Tokens; 21 | 22 | /** 23 | * @internal 24 | */ 25 | final class FirstClassCallableTransformer extends AbstractTransformer 26 | { 27 | public function getRequiredPhpVersionId(): int 28 | { 29 | return 8_01_00; 30 | } 31 | 32 | public function process(Tokens $tokens, Token $token, int $index): void 33 | { 34 | if ( 35 | $token->isGivenKind(T_ELLIPSIS) 36 | && $tokens[$tokens->getPrevMeaningfulToken($index)]->equals('(') 37 | && $tokens[$tokens->getNextMeaningfulToken($index)]->equals(')') 38 | ) { 39 | $tokens[$index] = new Token([CT::T_FIRST_CLASS_CALLABLE, '...']); 40 | } 41 | } 42 | 43 | public function getCustomTokens(): array 44 | { 45 | return [ 46 | CT::T_FIRST_CLASS_CALLABLE, 47 | ]; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/NamespaceOperatorTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTransformer; 18 | use PhpCsFixer\Tokenizer\CT; 19 | use PhpCsFixer\Tokenizer\Token; 20 | use PhpCsFixer\Tokenizer\Tokens; 21 | 22 | /** 23 | * Transform `namespace` operator from T_NAMESPACE into CT::T_NAMESPACE_OPERATOR. 24 | * 25 | * @author Gregor Harlan 26 | * 27 | * @internal 28 | */ 29 | final class NamespaceOperatorTransformer extends AbstractTransformer 30 | { 31 | public function getRequiredPhpVersionId(): int 32 | { 33 | return 5_03_00; 34 | } 35 | 36 | public function process(Tokens $tokens, Token $token, int $index): void 37 | { 38 | if (!$token->isGivenKind(T_NAMESPACE)) { 39 | return; 40 | } 41 | 42 | $nextIndex = $tokens->getNextMeaningfulToken($index); 43 | 44 | if ($tokens[$nextIndex]->isGivenKind(T_NS_SEPARATOR)) { 45 | $tokens[$index] = new Token([CT::T_NAMESPACE_OPERATOR, $token->getContent()]); 46 | } 47 | } 48 | 49 | public function getCustomTokens(): array 50 | { 51 | return [CT::T_NAMESPACE_OPERATOR]; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/ReturnRefTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTransformer; 18 | use PhpCsFixer\Tokenizer\CT; 19 | use PhpCsFixer\Tokenizer\Token; 20 | use PhpCsFixer\Tokenizer\Tokens; 21 | 22 | /** 23 | * Transform `&` operator into CT::T_RETURN_REF in `function & foo() {}`. 24 | * 25 | * @author Dariusz Rumiński 26 | * 27 | * @internal 28 | */ 29 | final class ReturnRefTransformer extends AbstractTransformer 30 | { 31 | public function getRequiredPhpVersionId(): int 32 | { 33 | return 5_00_00; 34 | } 35 | 36 | public function process(Tokens $tokens, Token $token, int $index): void 37 | { 38 | if ($token->equals('&') && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind([T_FUNCTION, T_FN])) { 39 | $tokens[$index] = new Token([CT::T_RETURN_REF, '&']); 40 | } 41 | } 42 | 43 | public function getCustomTokens(): array 44 | { 45 | return [CT::T_RETURN_REF]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/TypeAlternationTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTypeTransformer; 18 | use PhpCsFixer\Tokenizer\CT; 19 | use PhpCsFixer\Tokenizer\Token; 20 | use PhpCsFixer\Tokenizer\Tokens; 21 | 22 | /** 23 | * Transform `|` operator into CT::T_TYPE_ALTERNATION in `function foo(Type1 | Type2 $x) {` 24 | * or `} catch (ExceptionType1 | ExceptionType2 $e) {`. 25 | * 26 | * @author Dariusz Rumiński 27 | * 28 | * @internal 29 | */ 30 | final class TypeAlternationTransformer extends AbstractTypeTransformer 31 | { 32 | public function getPriority(): int 33 | { 34 | // needs to run after ArrayTypehintTransformer, TypeColonTransformer and AttributeTransformer 35 | return -15; 36 | } 37 | 38 | public function getRequiredPhpVersionId(): int 39 | { 40 | return 7_01_00; 41 | } 42 | 43 | public function process(Tokens $tokens, Token $token, int $index): void 44 | { 45 | $this->doProcess($tokens, $index, '|'); 46 | } 47 | 48 | public function getCustomTokens(): array 49 | { 50 | return [CT::T_TYPE_ALTERNATION]; 51 | } 52 | 53 | protected function replaceToken(Tokens $tokens, int $index): void 54 | { 55 | $tokens[$index] = new Token([CT::T_TYPE_ALTERNATION, '|']); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/TypeIntersectionTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTypeTransformer; 18 | use PhpCsFixer\Tokenizer\CT; 19 | use PhpCsFixer\Tokenizer\Token; 20 | use PhpCsFixer\Tokenizer\Tokens; 21 | 22 | /** 23 | * Transform `&` operator into CT::T_TYPE_INTERSECTION in `function foo(Type1 & Type2 $x) {` 24 | * or `} catch (ExceptionType1 & ExceptionType2 $e) {`. 25 | * 26 | * @internal 27 | */ 28 | final class TypeIntersectionTransformer extends AbstractTypeTransformer 29 | { 30 | public function getPriority(): int 31 | { 32 | // needs to run after ArrayTypehintTransformer, TypeColonTransformer and AttributeTransformer 33 | return -15; 34 | } 35 | 36 | public function getRequiredPhpVersionId(): int 37 | { 38 | return 8_01_00; 39 | } 40 | 41 | public function process(Tokens $tokens, Token $token, int $index): void 42 | { 43 | $this->doProcess($tokens, $index, [T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&']); 44 | } 45 | 46 | public function getCustomTokens(): array 47 | { 48 | return [CT::T_TYPE_INTERSECTION]; 49 | } 50 | 51 | protected function replaceToken(Tokens $tokens, int $index): void 52 | { 53 | $tokens[$index] = new Token([CT::T_TYPE_INTERSECTION, '&']); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Tokenizer/Transformer/WhitespacyCommentTransformer.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer\Tokenizer\Transformer; 16 | 17 | use PhpCsFixer\Tokenizer\AbstractTransformer; 18 | use PhpCsFixer\Tokenizer\Token; 19 | use PhpCsFixer\Tokenizer\Tokens; 20 | 21 | /** 22 | * Move trailing whitespaces from comments and docs into following T_WHITESPACE token. 23 | * 24 | * @author Dariusz Rumiński 25 | * 26 | * @internal 27 | */ 28 | final class WhitespacyCommentTransformer extends AbstractTransformer 29 | { 30 | public function getRequiredPhpVersionId(): int 31 | { 32 | return 5_00_00; 33 | } 34 | 35 | public function process(Tokens $tokens, Token $token, int $index): void 36 | { 37 | if (!$token->isComment()) { 38 | return; 39 | } 40 | 41 | $content = $token->getContent(); 42 | $trimmedContent = rtrim($content); 43 | 44 | // nothing trimmed, nothing to do 45 | if ($content === $trimmedContent) { 46 | return; 47 | } 48 | 49 | $whitespaces = substr($content, \strlen($trimmedContent)); 50 | 51 | $tokens[$index] = new Token([$token->getId(), $trimmedContent]); 52 | 53 | if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) { 54 | $tokens[$index + 1] = new Token([T_WHITESPACE, $whitespaces.$tokens[$index + 1]->getContent()]); 55 | } else { 56 | $tokens->insertAt($index + 1, new Token([T_WHITESPACE, $whitespaces])); 57 | } 58 | } 59 | 60 | public function getCustomTokens(): array 61 | { 62 | return []; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/ToolInfoInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * @internal 19 | */ 20 | interface ToolInfoInterface 21 | { 22 | /** 23 | * @return array{name: string, version: string, dist: array{reference?: string}} 24 | */ 25 | public function getComposerInstallationDetails(): array; 26 | 27 | public function getComposerVersion(): string; 28 | 29 | public function getVersion(): string; 30 | 31 | public function isInstalledAsPhar(): bool; 32 | 33 | public function isInstalledByComposer(): bool; 34 | 35 | public function isRunInsideDocker(): bool; 36 | 37 | public function getPharDownloadUri(string $version): string; 38 | } 39 | -------------------------------------------------------------------------------- /src/WhitespacesFixerConfig.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | */ 20 | final class WhitespacesFixerConfig 21 | { 22 | private string $indent; 23 | 24 | private string $lineEnding; 25 | 26 | public function __construct(string $indent = ' ', string $lineEnding = "\n") 27 | { 28 | if (!\in_array($indent, [' ', ' ', "\t"], true)) { 29 | throw new \InvalidArgumentException('Invalid "indent" param, expected tab or two or four spaces.'); 30 | } 31 | 32 | if (!\in_array($lineEnding, ["\n", "\r\n"], true)) { 33 | throw new \InvalidArgumentException('Invalid "lineEnding" param, expected "\n" or "\r\n".'); 34 | } 35 | 36 | $this->indent = $indent; 37 | $this->lineEnding = $lineEnding; 38 | } 39 | 40 | public function getIndent(): string 41 | { 42 | return $this->indent; 43 | } 44 | 45 | public function getLineEnding(): string 46 | { 47 | return $this->lineEnding; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/WordMatcher.php: -------------------------------------------------------------------------------- 1 | 9 | * Dariusz Rumiński 10 | * 11 | * This source file is subject to the MIT license that is bundled 12 | * with this source code in the file LICENSE. 13 | */ 14 | 15 | namespace PhpCsFixer; 16 | 17 | /** 18 | * @author Dariusz Rumiński 19 | * 20 | * @internal 21 | */ 22 | final class WordMatcher 23 | { 24 | /** 25 | * @var list 26 | */ 27 | private array $candidates; 28 | 29 | /** 30 | * @param list $candidates 31 | */ 32 | public function __construct(array $candidates) 33 | { 34 | $this->candidates = $candidates; 35 | } 36 | 37 | public function match(string $needle): ?string 38 | { 39 | $word = null; 40 | $distance = ceil(\strlen($needle) * 0.35); 41 | 42 | foreach ($this->candidates as $candidate) { 43 | $candidateDistance = levenshtein($needle, $candidate); 44 | 45 | if ($candidateDistance < $distance) { 46 | $word = $candidate; 47 | $distance = $candidateDistance; 48 | } 49 | } 50 | 51 | return $word; 52 | } 53 | } 54 | --------------------------------------------------------------------------------