Skip to content

Commit

Permalink
Add phan, php-cs-fixer, and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlmoon committed Nov 20, 2023
1 parent 05d253f commit 5620e15
Show file tree
Hide file tree
Showing 13 changed files with 758 additions and 72 deletions.
116 changes: 116 additions & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

use \Phan\Config;

/**
* This configuration will be read and overlayed on top of the
* default configuration. Command line arguments will be applied
* after this file is read.
*
* @see src/Phan/Config.php
* See Config for all configurable options.
*
* A Note About Paths
* ==================
*
* Files referenced from this file should be defined as
*
* ```
* Config::projectPath('relative_path/to/file')
* ```
*
* where the relative path is relative to the root of the
* project which is defined as either the working directory
* of the phan executable or a path passed in via the CLI
* '-d' flag.
*/
return [
// If true, missing properties will be created when
// they are first seen. If false, we'll report an
// error message.
"allow_missing_properties" => true,

// Allow null to be cast as any type and for any
// type to be cast to null.
"null_casts_as_any_type" => true,

// If this has entries, scalars (int, float, bool, string, null)
// are allowed to perform the casts listed.
// E.g. ['int' => ['float', 'string'], 'float' => ['int'], 'string' => ['int'], 'null' => ['string']]
// allows casting null to a string, but not vice versa.
// (subset of scalar_implicit_cast)
'scalar_implicit_partial' => [
'int' => ['float', 'string'],
'float' => ['int'],
'string' => ['int'],
'null' => ['string', 'bool'],
'bool' => ['null'],
],

// Backwards Compatibility Checking
'backward_compatibility_checks' => false,

// Run a quick version of checks that takes less
// time
"quick_mode" => true,

// Only emit critical issues
"minimum_severity" => 0,

// A set of fully qualified class-names for which
// a call to parent::__construct() is required
'parent_constructor_required' => [
],

// Add any issue types (such as 'PhanUndeclaredMethod')
// here to inhibit them from being reported
'suppress_issue_types' => [
// These report false positives in libraries due
// to them not being used by any of the other
// library code.
'PhanUnreferencedPublicClassConstant',
'PhanWriteOnlyProtectedProperty',
'PhanUnreferencedPublicMethod',
'PhanUnreferencedUseNormal',
'PhanUnreferencedProtectedMethod',
'PhanUnreferencedProtectedProperty',

],

// A list of directories that should be parsed for class and
// method information. After excluding the directories
// defined in exclude_analysis_directory_list, the remaining
// files will be statically analyzed for errors.
//
// Thus, both first-party and third-party code being used by
// your application should be included in this list.
'directory_list' => [
'src',
'vendor',
'tests',
],

// A list of directories holding code that we want
// to parse, but not analyze
"exclude_analysis_directory_list" => [
"vendor",
"tests",
],

// A file list that defines files that will be excluded
// from parsing and analysis and will not be read at all.
//
// This is useful for excluding hopelessly unanalyzable
// files that can't be removed for whatever reason.
'exclude_file_list' => [
],

// Set to true in order to attempt to detect dead
// (unreferenced) code. Keep in mind that the
// results will only be a guess given that classes,
// properties, constants and methods can be referenced
// as variables (like `$class->$property` or
// `$class->$method()`) in ways that we're unable
// to make sense of.
'dead_code_detection' => true,
];
68 changes: 68 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
;

return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'array_syntax' => [
'syntax' => 'short',
],
'binary_operator_spaces' => [
'default' => 'align_single_space',
],
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => ['statements' => ['return']],
'braces_position' => [
'allow_single_line_anonymous_functions' => true,
'allow_single_line_empty_anonymous_classes' => true,
'anonymous_classes_opening_brace' => 'same_line',
'anonymous_functions_opening_brace' => 'same_line',
'classes_opening_brace' => 'same_line',
'control_structures_opening_brace' => 'same_line',
'functions_opening_brace' => 'same_line',
],
'combine_consecutive_unsets' => true,
'concat_space' => [
'spacing' => 'one',
],
'declare_equal_normalize' => true,
'escape_implicit_backslashes' => [
'single_quoted' => true,
'double_quoted' => true,
],
'function_typehint_space' => true,
'include' => true,
'lowercase_cast' => true,
// 'class_attributes_separation' => ['elements' => ['method']],
'native_function_casing' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_statement' => true,
'no_mixed_echo_print' => [
'use' => 'echo',
],
'no_multiline_whitespace_around_double_arrow' => true,
'multiline_whitespace_before_semicolons' => false,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_unused_imports' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'object_operator_without_whitespace' => true,
'ordered_imports' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
])
->setFinder($finder)
;
29 changes: 26 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
"type": "library",
"license": "BSD-3-Clause",
"description": "PHP Library for implementing the Data Mapper pattern",
"config": {
"optimize-autoloader": true,
"discard-changes": true,
"sort-packages": true
},
"require": {
"php": "^8.0",
"dealnews/repository": "^3.0"
"dealnews/constraints": "^2.2.0",
"dealnews/repository": "^3.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.38",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpunit/phpunit": "^9.6"
},
"autoload": {
"psr-4": {
Expand All @@ -17,7 +28,19 @@
"DealNews\\DataMapper\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.1"
"scripts": {
"phan": [
"docker run --rm -e PHAN_DISABLE_XDEBUG_WARN=1 -v `pwd`:/mnt/src -w /mnt/src phanphp/phan:5 -p"
],
"test": [
"parallel-lint src/ tests/",
"phpunit --colors=never"
],
"lint": [
"parallel-lint src/ tests/"
],
"fix": [
"php-cs-fixer fix --config .php-cs-fixer.dist.php src tests"
]
}
}
13 changes: 10 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<coverage includeUncoveredFiles="true" processUncoveredFiles="false">
<include>
<directory>./src</directory>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./tests</directory>
<directory suffix=".php">./vendor</directory>
</exclude>
<report>
<text outputFile="php://stdout" showUncoveredFiles="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">./tests</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>
<groups>
Expand Down
Loading

0 comments on commit 5620e15

Please sign in to comment.