Documentation

DateMatch extends BaseMatch
in package

Tags
phpstan-consistent-constructor

Table of Contents

Constants

MAX_YEAR  = 2050
MIN_YEAR  = 1000
MIN_YEAR_SPACE  = 20
NUM_DAYS  = 31
NUM_MONTHS  = 12
NUM_YEARS  = 119
DATE_NO_SEPARATOR  = '/^\d{4,8}$/u'
DATE_WITH_SEPARATOR  = '/^(\d{1,4})([\s\/\\\\_.-])(\d{1,2})\2(\d{1,4})$/u'
(\d{1,4}) # day, month, year ([\s\/\\\\_.-]) # separator (\d{1,2}) # day, month \2 # same separator (\d{1,4}) # day, month, year

Properties

$begin  : mixed
$day  : int
$end  : mixed
$month  : int
$password  : mixed
$pattern  : mixed
$separator  : string
$token  : mixed
$year  : int
$DATE_SPLITS  : mixed

Methods

__construct()  : mixed
binom()  : float
Calculate binomial coefficient (n choose k).
findAll()  : array<string|int, mixed>
Find all occurrences of regular expression in a string.
getFeedback()  : array{'warning': string, "suggestions": string[]}
Get feedback to a user based on the match.
getGuesses()  : float
getGuessesLog10()  : float
getReferenceYear()  : int
match()  : array<string|int, DateMatch>
Match occurences of dates in a password
checkDate()  : array<string|int, mixed>|bool
datesWithoutSeparators()  : array<string|int, mixed>
Find dates without separators in a password.
datesWithSeparators()  : array<string|int, mixed>
Find dates with separators in a password.
getDistanceForMatchCandidate()  : int
getMinimumGuesses()  : float
getRawGuesses()  : float
mapIntsToDayMonth()  : array<string|int, mixed>|bool
removeRedundantMatches()  : array<string|int, mixed>
Removes date matches that are strict substrings of others.
twoToFourDigitYear()  : int

Constants

MIN_YEAR_SPACE

public mixed MIN_YEAR_SPACE = 20

DATE_NO_SEPARATOR

protected mixed DATE_NO_SEPARATOR = '/^\d{4,8}$/u'

DATE_WITH_SEPARATOR

(\d{1,4}) # day, month, year ([\s\/\\\\_.-]) # separator (\d{1,2}) # day, month \2 # same separator (\d{1,4}) # day, month, year

protected mixed DATE_WITH_SEPARATOR = '/^(\d{1,4})([\s\/\\\\_.-])(\d{1,2})\2(\d{1,4})$/u'

Properties

$day

public int $day

The day portion of the date in the token.

$month

public int $month

The month portion of the date in the token.

$separator

public string $separator

The separator used for the date in the token.

$year

public int $year

The year portion of the date in the token.

$DATE_SPLITS

private static mixed $DATE_SPLITS = [4 => [ # For length-4 strings, eg 1191 or 9111, two ways to split: [1, 2], # 1 1 91 (2nd split starts at index 1, 3rd at index 2) [2, 3], ], 5 => [ [1, 3], # 1 11 91 [2, 3], ], 6 => [ [1, 2], # 1 1 1991 [2, 4], # 11 11 91 [4, 5], ], 7 => [ [1, 3], # 1 11 1991 [2, 3], # 11 1 1991 [4, 5], # 1991 1 11 [4, 6], ], 8 => [ [2, 4], # 11 11 1991 [4, 6], ]]

Methods

__construct()

public __construct(string $password, int $begin, int $end, string $token, array<string|int, mixed> $params) : mixed
Parameters
$password : string
$begin : int
$end : int
$token : string
$params : array<string|int, mixed>

An array with keys: [day, month, year, separator].

binom()

Calculate binomial coefficient (n choose k).

public static binom(int $n, int $k) : float
Parameters
$n : int
$k : int
Return values
float

findAll()

Find all occurrences of regular expression in a string.

public static findAll(string $string, string $regex[, int $offset = 0 ]) : array<string|int, mixed>
Parameters
$string : string

String to search.

$regex : string

Regular expression with captures.

$offset : int = 0
Return values
array<string|int, mixed>

Array of capture groups. Captures in a group have named indexes: 'begin', 'end', 'token'. e.g. fishfish /(fish)/ array( array( array('begin' => 0, 'end' => 3, 'token' => 'fish'), array('begin' => 0, 'end' => 3, 'token' => 'fish') ), array( array('begin' => 4, 'end' => 7, 'token' => 'fish'), array('begin' => 4, 'end' => 7, 'token' => 'fish') ) )

getFeedback()

Get feedback to a user based on the match.

public getFeedback(bool $isSoleMatch) : array{'warning': string, "suggestions": string[]}
Parameters
$isSoleMatch : bool

Whether this is the only match in the password

Return values
array{'warning': string, "suggestions": string[]}

getGuesses()

public getGuesses() : float
Return values
float

getGuessesLog10()

public getGuessesLog10() : float
Return values
float

getReferenceYear()

public static getReferenceYear() : int
Return values
int

match()

Match occurences of dates in a password

public static match(string $password[, array<string|int, mixed> $userInputs = [] ]) : array<string|int, DateMatch>
Parameters
$password : string
$userInputs : array<string|int, mixed> = []
Return values
array<string|int, DateMatch>

checkDate()

protected static checkDate(array<string|int, int> $ints) : array<string|int, mixed>|bool
Parameters
$ints : array<string|int, int>

Three numbers in an array representing day, month and year (not necessarily in that order).

Return values
array<string|int, mixed>|bool

Returns an associative array containing 'day', 'month' and 'year' keys, or false if the provided date array is invalid.

datesWithoutSeparators()

Find dates without separators in a password.

protected static datesWithoutSeparators(string $password) : array<string|int, mixed>
Parameters
$password : string
Return values
array<string|int, mixed>

datesWithSeparators()

Find dates with separators in a password.

protected static datesWithSeparators(string $password) : array<string|int, mixed>
Parameters
$password : string
Return values
array<string|int, mixed>

getDistanceForMatchCandidate()

protected static getDistanceForMatchCandidate(array<string|int, mixed> $candidate) : int
Parameters
$candidate : array<string|int, mixed>
Return values
int

Returns the number of years between the detected year and the current year for a candidate.

getMinimumGuesses()

protected getMinimumGuesses() : float
Return values
float

getRawGuesses()

protected getRawGuesses() : float
Return values
float

mapIntsToDayMonth()

protected static mapIntsToDayMonth(array<string|int, int> $ints) : array<string|int, mixed>|bool
Parameters
$ints : array<string|int, int>

Two numbers in an array representing day and month (not necessarily in that order).

Return values
array<string|int, mixed>|bool

Returns an associative array containing 'day' and 'month' keys, or false if any combination of the two numbers does not match a day and month.

removeRedundantMatches()

Removes date matches that are strict substrings of others.

protected static removeRedundantMatches(array<string|int, mixed> $matches) : array<string|int, mixed>

This is helpful because the match function will contain matches for all valid date strings in a way that is tricky to capture with regexes only. While thorough, it will contain some unintuitive noise:

'2015_06_04', in addition to matching 2015_06_04, will also contain 5(!) other date matches: 15_06_04, 5_06_04, ..., even 2015 (matched as 5/1/2020)

Parameters
$matches : array<string|int, mixed>

An array of matches (not Match objects)

Return values
array<string|int, mixed>

The provided array of matches, but with matches that are strict substrings of others removed.

twoToFourDigitYear()

protected static twoToFourDigitYear(int $year) : int
Parameters
$year : int

A two digit number representing a year.

Return values
int

Returns the most likely four digit year for the provided number.


        
On this page

Search results