/** * @inheritDoc */ protected function validateArguments(array $args) { $valA = new HasTypeMap(['x' => 'integer']); $valB = new HasTypeMap(['x' => 'Chippyash\\Math\\Matrix\\NumericMatrix', 'y' => 'Chippyash\\Math\\Matrix\\NumericMatrix']); $valB1 = new Lambda(function ($args) { return $args['x']->is('Vector') && $args['y']->is('Vector'); }, new StringType(self::ERR2)); $valB2 = new Lambda(function ($args) { return $args['x']->vertices() == $args['y']->vertices(); }, new StringType(self::ERR1)); $validator = new LOr($valA, new LAnd($valB, new LAnd($valB1, $valB2))); if (!$validator->isValid($args)) { throw new InvalidParameterException(implode(':', $validator->getMessages())); } }
/** * @inheritDoc */ protected function validateArguments(array $args) { $valA1 = new HasTypeMap(['rows' => 'integer']); $valA2 = new Lambda(function ($args) { return $args['rows'] > 0 && !array_key_exists('cols', $args); }, new StringType(self::ERR1)); $valA = new LAnd($valA1, $valA2); $valB1 = new HasTypeMap(['rows' => 'integer', 'cols' => 'integer']); $valB2 = new Lambda(function ($args) { return $args['rows'] > 0 && $args['cols'] > 0; }, new StringType(self::ERR2)); $valB = new LAnd($valB1, $valB2); $validator = new LOr($valA, $valB); if (!$validator->isValid($args)) { throw new InvalidParameterException(implode(':', $validator->getMessages())); } }