fix: more php 8.2 and 8.3 fixes (#6330)
[openemr.git] / src / Validators / InsuranceCompanyValidator.php
blob60b329d6662aef7da9b1f72dbdc53faa2972e745
1 <?php
3 namespace OpenEMR\Validators;
5 use Particle\Validator\Validator;
7 /**
8 * Supports Insurance Company Record Validation.
10 * @package OpenEMR
11 * @link http://www.open-emr.org
12 * @author Vishnu Yarmaneni <vardhanvishnu@gmail.com>
13 * @copyright Copyright (c) 2021 Vishnu Yarmaneni <vardhanvishnu@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 class InsuranceCompanyValidator extends BaseValidator
18 /**
19 * Configures validations for the Insurance Company DB Insert and Update use-case.
20 * The update use-case is comprised of the same fields as the insert use-case.
21 * The update use-case differs from the insert use-case in that fields other than uuid are not required.
23 protected function configureValidator()
25 parent::configureValidator();
27 // insert validations
28 $this->validator->context(
29 self::DATABASE_INSERT_CONTEXT,
30 function (Validator $context) {
31 $context->required('name')->lengthBetween(2, 255);
32 $context->optional('attn')->lengthBetween(2, 255);
33 $context->optional('cms_id')->lengthBetween(2, 15);
34 $context->optional('alt_cms_id')->lengthBetween(2, 15);
35 $context->optional('ins_type_code')->numeric();
36 $context->optional('x12_receiver_id')->lengthBetween(2, 25);
37 $context->optional('x12_default_partner_id')->numeric();
41 // update validations copied from insert
42 $this->validator->context(
43 self::DATABASE_UPDATE_CONTEXT,
44 function (Validator $context) {
45 $context->copyContext(
46 self::DATABASE_INSERT_CONTEXT,
47 function ($rules) {
48 foreach ($rules as $key => $chain) {
49 $chain->required(false);
53 // additional uuid validation
54 $context->required("uuid", "Insurance UUID")->callback(function ($value) {
55 return $this->validateId("uuid", "insurance_companies", $value, true);
56 })->uuid();