diff --git a/.editorconfig b/.editorconfig index 0ea0cc46..c000d64f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,10 +1,812 @@ -# http://editorconfig.org -root = true - [*] +charset = utf-8 +end_of_line = lf +indent_size = 2 indent_style = space +insert_final_newline = false +max_line_length = 120 +tab_width = 2 +ij_continuation_indent_size = 4 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = false +ij_smart_tabs = false +ij_wrap_on_typing = false + +[*.blade.php] indent_size = 4 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true +tab_width = 4 +ij_continuation_indent_size = 8 +ij_blade_keep_indents_on_empty_lines = false + +[*.css] +ij_css_align_closing_brace_with_properties = false +ij_css_blank_lines_around_nested_selector = 1 +ij_css_blank_lines_between_blocks = 1 +ij_css_brace_placement = 0 +ij_css_enforce_quotes_on_format = false +ij_css_hex_color_long_format = false +ij_css_hex_color_lower_case = true +ij_css_hex_color_short_format = true +ij_css_hex_color_upper_case = false +ij_css_keep_blank_lines_in_code = 2 +ij_css_keep_indents_on_empty_lines = false +ij_css_keep_single_line_blocks = false +ij_css_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow +ij_css_space_after_colon = true +ij_css_space_before_opening_brace = true +ij_css_use_double_quotes = true +ij_css_value_alignment = 0 + +[*.csv] +max_line_length = 2147483647 +ij_csv_wrap_long_lines = false + +[*.feature] +tab_width = 4 +ij_continuation_indent_size = 8 +ij_gherkin_keep_indents_on_empty_lines = false + +[*.haml] +tab_width = 4 +ij_continuation_indent_size = 8 +ij_haml_keep_indents_on_empty_lines = false + +[*.less] +tab_width = 4 +ij_continuation_indent_size = 8 +ij_less_align_closing_brace_with_properties = false +ij_less_blank_lines_around_nested_selector = 1 +ij_less_blank_lines_between_blocks = 1 +ij_less_brace_placement = 0 +ij_less_enforce_quotes_on_format = false +ij_less_hex_color_long_format = false +ij_less_hex_color_lower_case = false +ij_less_hex_color_short_format = false +ij_less_hex_color_upper_case = false +ij_less_keep_blank_lines_in_code = 2 +ij_less_keep_indents_on_empty_lines = false +ij_less_keep_single_line_blocks = false +ij_less_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow +ij_less_space_after_colon = true +ij_less_space_before_opening_brace = true +ij_less_use_double_quotes = true +ij_less_value_alignment = 0 + +[*.neon] +indent_size = 4 +tab_width = 4 + +[*.sass] +ij_sass_align_closing_brace_with_properties = false +ij_sass_blank_lines_around_nested_selector = 1 +ij_sass_blank_lines_between_blocks = 1 +ij_sass_brace_placement = 0 +ij_sass_enforce_quotes_on_format = false +ij_sass_hex_color_long_format = false +ij_sass_hex_color_lower_case = false +ij_sass_hex_color_short_format = false +ij_sass_hex_color_upper_case = false +ij_sass_keep_blank_lines_in_code = 2 +ij_sass_keep_indents_on_empty_lines = false +ij_sass_keep_single_line_blocks = false +ij_sass_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow +ij_sass_space_after_colon = true +ij_sass_space_before_opening_brace = true +ij_sass_use_double_quotes = true +ij_sass_value_alignment = 0 + +[*.scss] +ij_scss_align_closing_brace_with_properties = false +ij_scss_blank_lines_around_nested_selector = 1 +ij_scss_blank_lines_between_blocks = 1 +ij_scss_brace_placement = 0 +ij_scss_enforce_quotes_on_format = false +ij_scss_hex_color_long_format = false +ij_scss_hex_color_lower_case = false +ij_scss_hex_color_short_format = false +ij_scss_hex_color_upper_case = false +ij_scss_keep_blank_lines_in_code = 2 +ij_scss_keep_indents_on_empty_lines = false +ij_scss_keep_single_line_blocks = false +ij_scss_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow +ij_scss_space_after_colon = true +ij_scss_space_before_opening_brace = true +ij_scss_use_double_quotes = true +ij_scss_value_alignment = 0 + +[*.twig] +ij_twig_keep_indents_on_empty_lines = false +ij_twig_spaces_inside_delimiters = true +ij_twig_spaces_inside_variable_delimiters = true + +[.editorconfig] +ij_editorconfig_align_group_field_declarations = false +ij_editorconfig_space_after_colon = false +ij_editorconfig_space_after_comma = true +ij_editorconfig_space_before_colon = false +ij_editorconfig_space_before_comma = false +ij_editorconfig_spaces_around_assignment_operators = true + +[{*.ats,*.ts}] +indent_size = 4 +tab_width = 4 +ij_typescript_align_imports = false +ij_typescript_align_multiline_array_initializer_expression = false +ij_typescript_align_multiline_binary_operation = false +ij_typescript_align_multiline_chained_methods = false +ij_typescript_align_multiline_extends_list = false +ij_typescript_align_multiline_for = true +ij_typescript_align_multiline_parameters = true +ij_typescript_align_multiline_parameters_in_calls = false +ij_typescript_align_multiline_ternary_operation = false +ij_typescript_align_object_properties = 0 +ij_typescript_align_union_types = false +ij_typescript_align_var_statements = 0 +ij_typescript_array_initializer_new_line_after_left_brace = false +ij_typescript_array_initializer_right_brace_on_new_line = false +ij_typescript_array_initializer_wrap = off +ij_typescript_assignment_wrap = off +ij_typescript_binary_operation_sign_on_next_line = false +ij_typescript_binary_operation_wrap = off +ij_typescript_blacklist_imports = rxjs/Rx,node_modules/**/*,@angular/material,@angular/material/typings/** +ij_typescript_blank_lines_after_imports = 1 +ij_typescript_blank_lines_around_class = 1 +ij_typescript_blank_lines_around_field = 0 +ij_typescript_blank_lines_around_field_in_interface = 0 +ij_typescript_blank_lines_around_function = 1 +ij_typescript_blank_lines_around_method = 1 +ij_typescript_blank_lines_around_method_in_interface = 1 +ij_typescript_block_brace_style = end_of_line +ij_typescript_call_parameters_new_line_after_left_paren = false +ij_typescript_call_parameters_right_paren_on_new_line = false +ij_typescript_call_parameters_wrap = off +ij_typescript_catch_on_new_line = false +ij_typescript_chained_call_dot_on_new_line = true +ij_typescript_class_brace_style = end_of_line +ij_typescript_comma_on_new_line = false +ij_typescript_do_while_brace_force = never +ij_typescript_else_on_new_line = false +ij_typescript_enforce_trailing_comma = keep +ij_typescript_extends_keyword_wrap = off +ij_typescript_extends_list_wrap = off +ij_typescript_field_prefix = _ +ij_typescript_file_name_style = relaxed +ij_typescript_finally_on_new_line = false +ij_typescript_for_brace_force = never +ij_typescript_for_statement_new_line_after_left_paren = false +ij_typescript_for_statement_right_paren_on_new_line = false +ij_typescript_for_statement_wrap = off +ij_typescript_force_quote_style = false +ij_typescript_force_semicolon_style = false +ij_typescript_function_expression_brace_style = end_of_line +ij_typescript_if_brace_force = never +ij_typescript_import_merge_members = global +ij_typescript_import_prefer_absolute_path = global +ij_typescript_import_sort_members = true +ij_typescript_import_sort_module_name = false +ij_typescript_import_use_node_resolution = true +ij_typescript_imports_wrap = on_every_item +ij_typescript_indent_case_from_switch = true +ij_typescript_indent_chained_calls = true +ij_typescript_indent_package_children = 0 +ij_typescript_jsdoc_include_types = false +ij_typescript_jsx_attribute_value = braces +ij_typescript_keep_blank_lines_in_code = 2 +ij_typescript_keep_first_column_comment = true +ij_typescript_keep_indents_on_empty_lines = false +ij_typescript_keep_line_breaks = true +ij_typescript_keep_simple_blocks_in_one_line = false +ij_typescript_keep_simple_methods_in_one_line = false +ij_typescript_line_comment_add_space = true +ij_typescript_line_comment_at_first_column = false +ij_typescript_method_brace_style = end_of_line +ij_typescript_method_call_chain_wrap = off +ij_typescript_method_parameters_new_line_after_left_paren = false +ij_typescript_method_parameters_right_paren_on_new_line = false +ij_typescript_method_parameters_wrap = off +ij_typescript_object_literal_wrap = on_every_item +ij_typescript_parentheses_expression_new_line_after_left_paren = false +ij_typescript_parentheses_expression_right_paren_on_new_line = false +ij_typescript_place_assignment_sign_on_next_line = false +ij_typescript_prefer_as_type_cast = false +ij_typescript_prefer_parameters_wrap = false +ij_typescript_reformat_c_style_comments = false +ij_typescript_space_after_colon = true +ij_typescript_space_after_comma = true +ij_typescript_space_after_dots_in_rest_parameter = false +ij_typescript_space_after_generator_mult = true +ij_typescript_space_after_property_colon = true +ij_typescript_space_after_quest = true +ij_typescript_space_after_type_colon = true +ij_typescript_space_after_unary_not = false +ij_typescript_space_before_async_arrow_lparen = true +ij_typescript_space_before_catch_keyword = true +ij_typescript_space_before_catch_left_brace = true +ij_typescript_space_before_catch_parentheses = true +ij_typescript_space_before_class_lbrace = true +ij_typescript_space_before_class_left_brace = true +ij_typescript_space_before_colon = true +ij_typescript_space_before_comma = false +ij_typescript_space_before_do_left_brace = true +ij_typescript_space_before_else_keyword = true +ij_typescript_space_before_else_left_brace = true +ij_typescript_space_before_finally_keyword = true +ij_typescript_space_before_finally_left_brace = true +ij_typescript_space_before_for_left_brace = true +ij_typescript_space_before_for_parentheses = true +ij_typescript_space_before_for_semicolon = false +ij_typescript_space_before_function_left_parenth = true +ij_typescript_space_before_generator_mult = false +ij_typescript_space_before_if_left_brace = true +ij_typescript_space_before_if_parentheses = true +ij_typescript_space_before_method_call_parentheses = false +ij_typescript_space_before_method_left_brace = true +ij_typescript_space_before_method_parentheses = false +ij_typescript_space_before_property_colon = false +ij_typescript_space_before_quest = true +ij_typescript_space_before_switch_left_brace = true +ij_typescript_space_before_switch_parentheses = true +ij_typescript_space_before_try_left_brace = true +ij_typescript_space_before_type_colon = false +ij_typescript_space_before_unary_not = false +ij_typescript_space_before_while_keyword = true +ij_typescript_space_before_while_left_brace = true +ij_typescript_space_before_while_parentheses = true +ij_typescript_spaces_around_additive_operators = true +ij_typescript_spaces_around_arrow_function_operator = true +ij_typescript_spaces_around_assignment_operators = true +ij_typescript_spaces_around_bitwise_operators = true +ij_typescript_spaces_around_equality_operators = true +ij_typescript_spaces_around_logical_operators = true +ij_typescript_spaces_around_multiplicative_operators = true +ij_typescript_spaces_around_relational_operators = true +ij_typescript_spaces_around_shift_operators = true +ij_typescript_spaces_around_unary_operator = false +ij_typescript_spaces_within_array_initializer_brackets = false +ij_typescript_spaces_within_brackets = false +ij_typescript_spaces_within_catch_parentheses = false +ij_typescript_spaces_within_for_parentheses = false +ij_typescript_spaces_within_if_parentheses = false +ij_typescript_spaces_within_imports = false +ij_typescript_spaces_within_interpolation_expressions = false +ij_typescript_spaces_within_method_call_parentheses = false +ij_typescript_spaces_within_method_parentheses = false +ij_typescript_spaces_within_object_literal_braces = false +ij_typescript_spaces_within_object_type_braces = true +ij_typescript_spaces_within_parentheses = false +ij_typescript_spaces_within_switch_parentheses = false +ij_typescript_spaces_within_type_assertion = false +ij_typescript_spaces_within_union_types = true +ij_typescript_spaces_within_while_parentheses = false +ij_typescript_special_else_if_treatment = true +ij_typescript_ternary_operation_signs_on_next_line = false +ij_typescript_ternary_operation_wrap = off +ij_typescript_union_types_wrap = on_every_item +ij_typescript_use_chained_calls_group_indents = false +ij_typescript_use_double_quotes = true +ij_typescript_use_explicit_js_extension = global +ij_typescript_use_path_mapping = always +ij_typescript_use_public_modifier = false +ij_typescript_use_semicolon_after_statement = true +ij_typescript_var_declaration_wrap = normal +ij_typescript_while_brace_force = never +ij_typescript_while_on_new_line = false +ij_typescript_wrap_comments = false + +[{*.cjs,*.js}] +ij_javascript_align_imports = false +ij_javascript_align_multiline_array_initializer_expression = true +ij_javascript_align_multiline_binary_operation = false +ij_javascript_align_multiline_chained_methods = true +ij_javascript_align_multiline_extends_list = false +ij_javascript_align_multiline_for = true +ij_javascript_align_multiline_parameters = true +ij_javascript_align_multiline_parameters_in_calls = false +ij_javascript_align_multiline_ternary_operation = false +ij_javascript_align_object_properties = 1 +ij_javascript_align_union_types = false +ij_javascript_align_var_statements = 2 +ij_javascript_array_initializer_new_line_after_left_brace = true +ij_javascript_array_initializer_right_brace_on_new_line = true +ij_javascript_array_initializer_wrap = split_into_lines +ij_javascript_assignment_wrap = off +ij_javascript_binary_operation_sign_on_next_line = false +ij_javascript_binary_operation_wrap = off +ij_javascript_blacklist_imports = rxjs/Rx,node_modules/**/*,@angular/material,@angular/material/typings/** +ij_javascript_blank_lines_after_imports = 1 +ij_javascript_blank_lines_around_class = 1 +ij_javascript_blank_lines_around_field = 0 +ij_javascript_blank_lines_around_function = 1 +ij_javascript_blank_lines_around_method = 1 +ij_javascript_block_brace_style = end_of_line +ij_javascript_call_parameters_new_line_after_left_paren = false +ij_javascript_call_parameters_right_paren_on_new_line = false +ij_javascript_call_parameters_wrap = off +ij_javascript_catch_on_new_line = true +ij_javascript_chained_call_dot_on_new_line = true +ij_javascript_class_brace_style = end_of_line +ij_javascript_comma_on_new_line = false +ij_javascript_do_while_brace_force = always +ij_javascript_else_on_new_line = false +ij_javascript_enforce_trailing_comma = keep +ij_javascript_extends_keyword_wrap = off +ij_javascript_extends_list_wrap = off +ij_javascript_field_prefix = _ +ij_javascript_file_name_style = relaxed +ij_javascript_finally_on_new_line = true +ij_javascript_for_brace_force = always +ij_javascript_for_statement_new_line_after_left_paren = false +ij_javascript_for_statement_right_paren_on_new_line = false +ij_javascript_for_statement_wrap = off +ij_javascript_force_quote_style = false +ij_javascript_force_semicolon_style = false +ij_javascript_function_expression_brace_style = end_of_line +ij_javascript_if_brace_force = always +ij_javascript_import_merge_members = global +ij_javascript_import_prefer_absolute_path = global +ij_javascript_import_sort_members = true +ij_javascript_import_sort_module_name = false +ij_javascript_import_use_node_resolution = true +ij_javascript_imports_wrap = on_every_item +ij_javascript_indent_case_from_switch = true +ij_javascript_indent_chained_calls = true +ij_javascript_indent_package_children = 0 +ij_javascript_jsx_attribute_value = braces +ij_javascript_keep_blank_lines_in_code = 2 +ij_javascript_keep_first_column_comment = false +ij_javascript_keep_indents_on_empty_lines = false +ij_javascript_keep_line_breaks = true +ij_javascript_keep_simple_blocks_in_one_line = true +ij_javascript_keep_simple_methods_in_one_line = true +ij_javascript_line_comment_add_space = true +ij_javascript_line_comment_at_first_column = true +ij_javascript_method_brace_style = end_of_line +ij_javascript_method_call_chain_wrap = off +ij_javascript_method_parameters_new_line_after_left_paren = false +ij_javascript_method_parameters_right_paren_on_new_line = false +ij_javascript_method_parameters_wrap = off +ij_javascript_object_literal_wrap = split_into_lines +ij_javascript_parentheses_expression_new_line_after_left_paren = false +ij_javascript_parentheses_expression_right_paren_on_new_line = false +ij_javascript_place_assignment_sign_on_next_line = false +ij_javascript_prefer_as_type_cast = false +ij_javascript_prefer_parameters_wrap = false +ij_javascript_reformat_c_style_comments = false +ij_javascript_space_after_colon = true +ij_javascript_space_after_comma = true +ij_javascript_space_after_dots_in_rest_parameter = false +ij_javascript_space_after_generator_mult = true +ij_javascript_space_after_property_colon = true +ij_javascript_space_after_quest = true +ij_javascript_space_after_type_colon = true +ij_javascript_space_after_unary_not = false +ij_javascript_space_before_async_arrow_lparen = true +ij_javascript_space_before_catch_keyword = true +ij_javascript_space_before_catch_left_brace = true +ij_javascript_space_before_catch_parentheses = true +ij_javascript_space_before_class_lbrace = true +ij_javascript_space_before_class_left_brace = true +ij_javascript_space_before_colon = true +ij_javascript_space_before_comma = false +ij_javascript_space_before_do_left_brace = true +ij_javascript_space_before_else_keyword = true +ij_javascript_space_before_else_left_brace = true +ij_javascript_space_before_finally_keyword = true +ij_javascript_space_before_finally_left_brace = true +ij_javascript_space_before_for_left_brace = true +ij_javascript_space_before_for_parentheses = true +ij_javascript_space_before_for_semicolon = false +ij_javascript_space_before_function_left_parenth = false +ij_javascript_space_before_generator_mult = false +ij_javascript_space_before_if_left_brace = true +ij_javascript_space_before_if_parentheses = true +ij_javascript_space_before_method_call_parentheses = false +ij_javascript_space_before_method_left_brace = true +ij_javascript_space_before_method_parentheses = false +ij_javascript_space_before_property_colon = false +ij_javascript_space_before_quest = true +ij_javascript_space_before_switch_left_brace = true +ij_javascript_space_before_switch_parentheses = true +ij_javascript_space_before_try_left_brace = true +ij_javascript_space_before_type_colon = false +ij_javascript_space_before_unary_not = false +ij_javascript_space_before_while_keyword = true +ij_javascript_space_before_while_left_brace = true +ij_javascript_space_before_while_parentheses = true +ij_javascript_spaces_around_additive_operators = true +ij_javascript_spaces_around_arrow_function_operator = true +ij_javascript_spaces_around_assignment_operators = true +ij_javascript_spaces_around_bitwise_operators = true +ij_javascript_spaces_around_equality_operators = true +ij_javascript_spaces_around_logical_operators = true +ij_javascript_spaces_around_multiplicative_operators = true +ij_javascript_spaces_around_relational_operators = true +ij_javascript_spaces_around_shift_operators = true +ij_javascript_spaces_around_unary_operator = false +ij_javascript_spaces_within_array_initializer_brackets = false +ij_javascript_spaces_within_brackets = false +ij_javascript_spaces_within_catch_parentheses = false +ij_javascript_spaces_within_for_parentheses = false +ij_javascript_spaces_within_if_parentheses = false +ij_javascript_spaces_within_imports = false +ij_javascript_spaces_within_interpolation_expressions = false +ij_javascript_spaces_within_method_call_parentheses = false +ij_javascript_spaces_within_method_parentheses = false +ij_javascript_spaces_within_object_literal_braces = true +ij_javascript_spaces_within_object_type_braces = true +ij_javascript_spaces_within_parentheses = false +ij_javascript_spaces_within_switch_parentheses = false +ij_javascript_spaces_within_type_assertion = false +ij_javascript_spaces_within_union_types = true +ij_javascript_spaces_within_while_parentheses = false +ij_javascript_special_else_if_treatment = true +ij_javascript_ternary_operation_signs_on_next_line = false +ij_javascript_ternary_operation_wrap = off +ij_javascript_union_types_wrap = on_every_item +ij_javascript_use_chained_calls_group_indents = false +ij_javascript_use_double_quotes = true +ij_javascript_use_explicit_js_extension = global +ij_javascript_use_path_mapping = always +ij_javascript_use_public_modifier = false +ij_javascript_use_semicolon_after_statement = true +ij_javascript_var_declaration_wrap = normal +ij_javascript_while_brace_force = always +ij_javascript_while_on_new_line = false +ij_javascript_wrap_comments = true + +[{*.cjsx,*.coffee}] +ij_continuation_indent_size = 2 +ij_coffeescript_align_function_body = false +ij_coffeescript_align_imports = false +ij_coffeescript_align_multiline_array_initializer_expression = true +ij_coffeescript_align_multiline_parameters = true +ij_coffeescript_align_multiline_parameters_in_calls = false +ij_coffeescript_align_object_properties = 0 +ij_coffeescript_align_union_types = false +ij_coffeescript_align_var_statements = 0 +ij_coffeescript_array_initializer_new_line_after_left_brace = false +ij_coffeescript_array_initializer_right_brace_on_new_line = false +ij_coffeescript_array_initializer_wrap = normal +ij_coffeescript_blacklist_imports = rxjs/Rx,node_modules/**/*,@angular/material,@angular/material/typings/** +ij_coffeescript_blank_lines_around_function = 1 +ij_coffeescript_call_parameters_new_line_after_left_paren = false +ij_coffeescript_call_parameters_right_paren_on_new_line = false +ij_coffeescript_call_parameters_wrap = normal +ij_coffeescript_chained_call_dot_on_new_line = true +ij_coffeescript_comma_on_new_line = false +ij_coffeescript_enforce_trailing_comma = keep +ij_coffeescript_field_prefix = _ +ij_coffeescript_file_name_style = relaxed +ij_coffeescript_force_quote_style = false +ij_coffeescript_force_semicolon_style = false +ij_coffeescript_function_expression_brace_style = end_of_line +ij_coffeescript_import_merge_members = global +ij_coffeescript_import_prefer_absolute_path = global +ij_coffeescript_import_sort_members = true +ij_coffeescript_import_sort_module_name = false +ij_coffeescript_import_use_node_resolution = true +ij_coffeescript_imports_wrap = on_every_item +ij_coffeescript_indent_chained_calls = true +ij_coffeescript_indent_package_children = 0 +ij_coffeescript_jsx_attribute_value = braces +ij_coffeescript_keep_blank_lines_in_code = 2 +ij_coffeescript_keep_first_column_comment = true +ij_coffeescript_keep_indents_on_empty_lines = false +ij_coffeescript_keep_line_breaks = true +ij_coffeescript_keep_simple_methods_in_one_line = false +ij_coffeescript_method_parameters_new_line_after_left_paren = false +ij_coffeescript_method_parameters_right_paren_on_new_line = false +ij_coffeescript_method_parameters_wrap = off +ij_coffeescript_object_literal_wrap = on_every_item +ij_coffeescript_prefer_as_type_cast = false +ij_coffeescript_reformat_c_style_comments = false +ij_coffeescript_space_after_comma = true +ij_coffeescript_space_after_dots_in_rest_parameter = false +ij_coffeescript_space_after_generator_mult = true +ij_coffeescript_space_after_property_colon = true +ij_coffeescript_space_after_type_colon = true +ij_coffeescript_space_after_unary_not = false +ij_coffeescript_space_before_async_arrow_lparen = true +ij_coffeescript_space_before_class_lbrace = true +ij_coffeescript_space_before_comma = false +ij_coffeescript_space_before_function_left_parenth = true +ij_coffeescript_space_before_generator_mult = false +ij_coffeescript_space_before_property_colon = false +ij_coffeescript_space_before_type_colon = false +ij_coffeescript_space_before_unary_not = false +ij_coffeescript_spaces_around_additive_operators = true +ij_coffeescript_spaces_around_arrow_function_operator = true +ij_coffeescript_spaces_around_assignment_operators = true +ij_coffeescript_spaces_around_bitwise_operators = true +ij_coffeescript_spaces_around_equality_operators = true +ij_coffeescript_spaces_around_logical_operators = true +ij_coffeescript_spaces_around_multiplicative_operators = true +ij_coffeescript_spaces_around_relational_operators = true +ij_coffeescript_spaces_around_shift_operators = true +ij_coffeescript_spaces_around_unary_operator = false +ij_coffeescript_spaces_within_array_initializer_braces = false +ij_coffeescript_spaces_within_array_initializer_brackets = false +ij_coffeescript_spaces_within_imports = false +ij_coffeescript_spaces_within_index_brackets = false +ij_coffeescript_spaces_within_interpolation_expressions = false +ij_coffeescript_spaces_within_method_call_parentheses = false +ij_coffeescript_spaces_within_method_parentheses = false +ij_coffeescript_spaces_within_object_braces = false +ij_coffeescript_spaces_within_object_literal_braces = false +ij_coffeescript_spaces_within_object_type_braces = true +ij_coffeescript_spaces_within_range_brackets = false +ij_coffeescript_spaces_within_type_assertion = false +ij_coffeescript_spaces_within_union_types = true +ij_coffeescript_union_types_wrap = on_every_item +ij_coffeescript_use_chained_calls_group_indents = false +ij_coffeescript_use_double_quotes = true +ij_coffeescript_use_explicit_js_extension = global +ij_coffeescript_use_path_mapping = always +ij_coffeescript_use_public_modifier = false +ij_coffeescript_use_semicolon_after_statement = false +ij_coffeescript_var_declaration_wrap = normal + +[{*.module,*.php_cs,*.hphp,*.phtml,*.php5,*.php4,*.php,*.ctp,*.inc}] +indent_size = 4 +tab_width = 4 +ij_smart_tabs = true +ij_php_align_assignments = false +ij_php_align_class_constants = true +ij_php_align_group_field_declarations = true +ij_php_align_inline_comments = false +ij_php_align_key_value_pairs = true +ij_php_align_multiline_array_initializer_expression = true +ij_php_align_multiline_binary_operation = true +ij_php_align_multiline_chained_methods = true +ij_php_align_multiline_extends_list = true +ij_php_align_multiline_for = true +ij_php_align_multiline_parameters = true +ij_php_align_multiline_parameters_in_calls = true +ij_php_align_multiline_ternary_operation = false +ij_php_align_phpdoc_comments = true +ij_php_align_phpdoc_param_names = true +ij_php_anonymous_brace_style = end_of_line +ij_php_api_weight = 28 +ij_php_array_initializer_new_line_after_left_brace = true +ij_php_array_initializer_right_brace_on_new_line = true +ij_php_array_initializer_wrap = on_every_item +ij_php_assignment_wrap = off +ij_php_author_weight = 28 +ij_php_binary_operation_sign_on_next_line = false +ij_php_binary_operation_wrap = off +ij_php_blank_lines_after_class_header = 0 +ij_php_blank_lines_after_function = 1 +ij_php_blank_lines_after_imports = 1 +ij_php_blank_lines_after_opening_tag = 0 +ij_php_blank_lines_after_package = 1 +ij_php_blank_lines_around_class = 1 +ij_php_blank_lines_around_constants = 0 +ij_php_blank_lines_around_field = 0 +ij_php_blank_lines_around_method = 1 +ij_php_blank_lines_before_class_end = 0 +ij_php_blank_lines_before_imports = 1 +ij_php_blank_lines_before_method_body = 0 +ij_php_blank_lines_before_package = 1 +ij_php_blank_lines_before_return_statement = 1 +ij_php_blank_lines_between_imports = 0 +ij_php_block_brace_style = end_of_line +ij_php_call_parameters_new_line_after_left_paren = true +ij_php_call_parameters_right_paren_on_new_line = true +ij_php_call_parameters_wrap = off +ij_php_catch_on_new_line = false +ij_php_category_weight = 28 +ij_php_class_brace_style = next_line +ij_php_comma_after_last_array_element = true +ij_php_concat_spaces = true +ij_php_copyright_weight = 28 +ij_php_deprecated_weight = 28 +ij_php_do_while_brace_force = always +ij_php_else_if_style = as_is +ij_php_else_on_new_line = false +ij_php_example_weight = 28 +ij_php_extends_keyword_wrap = off +ij_php_extends_list_wrap = off +ij_php_fields_default_visibility = private +ij_php_filesource_weight = 28 +ij_php_finally_on_new_line = false +ij_php_for_brace_force = always +ij_php_for_statement_new_line_after_left_paren = false +ij_php_for_statement_right_paren_on_new_line = false +ij_php_for_statement_wrap = on_every_item +ij_php_force_short_declaration_array_style = true +ij_php_global_weight = 28 +ij_php_group_use_wrap = on_every_item +ij_php_if_brace_force = always +ij_php_if_lparen_on_next_line = false +ij_php_if_rparen_on_next_line = false +ij_php_ignore_weight = 28 +ij_php_import_sorting = alphabetic +ij_php_indent_break_from_case = true +ij_php_indent_case_from_switch = true +ij_php_indent_code_in_php_tags = false +ij_php_internal_weight = 28 +ij_php_keep_blank_lines_after_lbrace = 2 +ij_php_keep_blank_lines_before_right_brace = 2 +ij_php_keep_blank_lines_in_code = 2 +ij_php_keep_blank_lines_in_declarations = 2 +ij_php_keep_control_statement_in_one_line = false +ij_php_keep_first_column_comment = false +ij_php_keep_indents_on_empty_lines = false +ij_php_keep_line_breaks = true +ij_php_keep_rparen_and_lbrace_on_one_line = false +ij_php_keep_simple_methods_in_one_line = false +ij_php_lambda_brace_style = end_of_line +ij_php_license_weight = 28 +ij_php_line_comment_add_space = false +ij_php_line_comment_at_first_column = true +ij_php_link_weight = 28 +ij_php_lower_case_boolean_const = true +ij_php_lower_case_null_const = true +ij_php_method_brace_style = next_line +ij_php_method_call_chain_wrap = on_every_item +ij_php_method_parameters_new_line_after_left_paren = false +ij_php_method_parameters_right_paren_on_new_line = false +ij_php_method_parameters_wrap = off +ij_php_method_weight = 28 +ij_php_modifier_list_wrap = false +ij_php_multiline_chained_calls_semicolon_on_new_line = false +ij_php_namespace_brace_style = 1 +ij_php_null_type_position = in_the_end +ij_php_package_weight = 28 +ij_php_param_weight = 0 +ij_php_parentheses_expression_new_line_after_left_paren = false +ij_php_parentheses_expression_right_paren_on_new_line = false +ij_php_phpdoc_blank_line_before_tags = true +ij_php_phpdoc_blank_lines_around_parameters = true +ij_php_phpdoc_keep_blank_lines = true +ij_php_phpdoc_param_spaces_between_name_and_description = 1 +ij_php_phpdoc_param_spaces_between_tag_and_type = 1 +ij_php_phpdoc_param_spaces_between_type_and_name = 1 +ij_php_phpdoc_use_fqcn = true +ij_php_phpdoc_wrap_long_lines = true +ij_php_place_assignment_sign_on_next_line = false +ij_php_place_parens_for_constructor = 0 +ij_php_property_read_weight = 28 +ij_php_property_weight = 28 +ij_php_property_write_weight = 28 +ij_php_return_type_on_new_line = false +ij_php_return_weight = 1 +ij_php_see_weight = 28 +ij_php_since_weight = 28 +ij_php_sort_phpdoc_elements = true +ij_php_space_after_colon = true +ij_php_space_after_colon_in_return_type = true +ij_php_space_after_comma = true +ij_php_space_after_for_semicolon = true +ij_php_space_after_quest = true +ij_php_space_after_type_cast = false +ij_php_space_after_unary_not = false +ij_php_space_before_array_initializer_left_brace = false +ij_php_space_before_catch_keyword = true +ij_php_space_before_catch_left_brace = true +ij_php_space_before_catch_parentheses = true +ij_php_space_before_class_left_brace = true +ij_php_space_before_closure_left_parenthesis = true +ij_php_space_before_colon = true +ij_php_space_before_colon_in_return_type = false +ij_php_space_before_comma = false +ij_php_space_before_do_left_brace = true +ij_php_space_before_else_keyword = true +ij_php_space_before_else_left_brace = true +ij_php_space_before_finally_keyword = true +ij_php_space_before_finally_left_brace = true +ij_php_space_before_for_left_brace = true +ij_php_space_before_for_parentheses = true +ij_php_space_before_for_semicolon = false +ij_php_space_before_if_left_brace = true +ij_php_space_before_if_parentheses = true +ij_php_space_before_method_call_parentheses = false +ij_php_space_before_method_left_brace = true +ij_php_space_before_method_parentheses = false +ij_php_space_before_quest = true +ij_php_space_before_switch_left_brace = true +ij_php_space_before_switch_parentheses = true +ij_php_space_before_try_left_brace = true +ij_php_space_before_unary_not = false +ij_php_space_before_while_keyword = true +ij_php_space_before_while_left_brace = true +ij_php_space_before_while_parentheses = true +ij_php_space_between_ternary_quest_and_colon = false +ij_php_spaces_around_additive_operators = true +ij_php_spaces_around_arrow = false +ij_php_spaces_around_assignment_in_declare = false +ij_php_spaces_around_assignment_operators = true +ij_php_spaces_around_bitwise_operators = true +ij_php_spaces_around_equality_operators = true +ij_php_spaces_around_logical_operators = true +ij_php_spaces_around_multiplicative_operators = true +ij_php_spaces_around_null_coalesce_operator = true +ij_php_spaces_around_relational_operators = true +ij_php_spaces_around_shift_operators = true +ij_php_spaces_around_unary_operator = false +ij_php_spaces_around_var_within_brackets = false +ij_php_spaces_within_array_initializer_braces = false +ij_php_spaces_within_brackets = false +ij_php_spaces_within_catch_parentheses = false +ij_php_spaces_within_for_parentheses = false +ij_php_spaces_within_if_parentheses = false +ij_php_spaces_within_method_call_parentheses = false +ij_php_spaces_within_method_parentheses = false +ij_php_spaces_within_parentheses = false +ij_php_spaces_within_short_echo_tags = true +ij_php_spaces_within_switch_parentheses = false +ij_php_spaces_within_while_parentheses = false +ij_php_special_else_if_treatment = true +ij_php_subpackage_weight = 28 +ij_php_ternary_operation_signs_on_next_line = false +ij_php_ternary_operation_wrap = off +ij_php_throws_weight = 2 +ij_php_todo_weight = 28 +ij_php_unknown_tag_weight = 28 +ij_php_upper_case_boolean_const = false +ij_php_upper_case_null_const = false +ij_php_uses_weight = 28 +ij_php_var_weight = 28 +ij_php_variable_naming_style = mixed +ij_php_version_weight = 28 +ij_php_while_brace_force = always +ij_php_while_on_new_line = false + +[{*.sht,*.htm,*.html,*.shtm,*.shtml,*.ng}] +ij_html_add_new_line_before_tags = body,div,p,form,h1,h2,h3 +ij_html_align_attributes = true +ij_html_align_text = false +ij_html_attribute_wrap = off +ij_html_block_comment_at_first_column = true +ij_html_do_not_align_children_of_min_lines = 0 +ij_html_do_not_break_if_inline_tags = title,h1,h2,h3,h4,h5,h6 +ij_html_do_not_indent_children_of_tags = html,body,thead,tbody,tfoot +ij_html_enforce_quotes = false +ij_html_inline_tags = a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var +ij_html_keep_blank_lines = 2 +ij_html_keep_indents_on_empty_lines = false +ij_html_keep_line_breaks = true +ij_html_keep_line_breaks_in_text = true +ij_html_keep_whitespaces = false +ij_html_keep_whitespaces_inside = span,pre,textarea +ij_html_line_comment_at_first_column = true +ij_html_new_line_after_last_attribute = never +ij_html_new_line_before_first_attribute = never +ij_html_quote_style = double +ij_html_remove_new_line_before_tags = br +ij_html_space_after_tag_name = false +ij_html_space_around_equality_in_attribute = false +ij_html_space_inside_empty_tag = true +ij_html_text_wrap = off + +[{*.yml,*.yaml}] +ij_yaml_keep_indents_on_empty_lines = false +ij_yaml_keep_line_breaks = true + +[{*.zsh,*.bash,*.sh}] +ij_shell_binary_ops_start_line = false +ij_shell_keep_column_alignment_padding = false +ij_shell_minify_program = false +ij_shell_redirect_followed_by_space = false +ij_shell_switch_cases_indented = false + +[{composer.lock,.eslintrc,bowerrc,.babelrc,jest.config,.stylelintrc,*.jsb3,*.jsb2,*.json}] +ij_json_keep_blank_lines_in_code = 0 +ij_json_keep_indents_on_empty_lines = false +ij_json_keep_line_breaks = true +ij_json_space_after_colon = true +ij_json_space_after_comma = true +ij_json_space_before_colon = true +ij_json_space_before_comma = false +ij_json_spaces_within_braces = false +ij_json_spaces_within_brackets = false +ij_json_wrap_long_lines = false + +[{phpunit.xml.dist,*.jhm,*.xul,*.rng,*.wsdl,*.fxml,*.xslt,*.jrxml,*.ant,*.xsl,*.xsd,*.tld,*.jnlp,*.s3db,*.xml}] +indent_size = 4 +tab_width = 4 +ij_continuation_indent_size = 8 +ij_xml_block_comment_at_first_column = true +ij_xml_keep_indents_on_empty_lines = false +ij_xml_line_comment_at_first_column = true diff --git a/.gitattributes b/.gitattributes index c3ce6a26..f4ef1b97 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,3 +6,5 @@ /.gitignore export-ignore /.travis.yml export-ignore /phpunit.xml export-ignore +/phpcs.php_cs export-ignore +/phpstan.neon export-ignore diff --git a/.travis.yml b/.travis.yml index 9c4fdfa3..f938c68c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,19 +11,22 @@ matrix: - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 - php: nightly before_script: - php --version - wget https://scrutinizer-ci.com/ocular.phar - travis_retry composer self-update - - travis_retry composer require satooshi/php-coveralls:1.0.0 + - travis_retry composer require satooshi/php-coveralls + - if [ "$(phpenv version-name)" == 7.3 ]; then travis_retry composer require phpstan/phpstan; fi - travis_retry composer install --no-interaction --prefer-source - composer dump-autoload -o script: - mkdir -p build/logs - php vendor/bin/phpunit -c phpunit.xml --debug + - if [ "$(phpenv version-name)" == 7.3 ]; then php vendor/bin/phpstan analyse; fi after_script: - php vendor/bin/coveralls -v diff --git a/composer.json b/composer.json index ab2184af..bd90cd54 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,12 @@ { "name": "sabas/edifact", "description": "Tools in PHP for UN/EDIFACT", - "keywords": ["EDI", "EDIFACT", "message", "container"], + "keywords": [ + "EDI", + "EDIFACT", + "message", + "container" + ], "homepage": "https://github.com/php-edifact/edifact", "license": "LGPL-3.0-or-later", "authors": [ @@ -20,28 +25,28 @@ "role": "Developer" } ], - "support": { - "issues": "https://github.com/php-edifact/edifact/issues" - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/php-edifact/edifact" - } - ], "require": { "php": ">=7.0.0", - "ext-simplexml": "*", "ext-json": "*", - "voku/arrayy": "5.*" + "ext-simplexml": "*", + "voku/arrayy": "~7.1" }, "require-dev": { - "phpunit/phpunit": "~6.0", - "php-edifact/edifact-mapping": "dev-master" + "php-edifact/edifact-mapping": "dev-master", + "phpunit/phpunit": "~6.0" }, "autoload": { "psr-4": { "EDI\\": "src/EDI/" } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/php-edifact/edifact" + } + ], + "support": { + "issues": "https://github.com/php-edifact/edifact/issues" } } diff --git a/phpcs.php_cs b/phpcs.php_cs new file mode 100644 index 00000000..c68ee362 --- /dev/null +++ b/phpcs.php_cs @@ -0,0 +1,238 @@ +setUsingCache(false) + ->setRiskyAllowed(true) + ->setRules( + [ + 'align_multiline_comment' => [ + 'comment_type' => 'all_multiline', + ], + 'array_indentation' => true, + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'backtick_to_shell_exec' => true, + 'binary_operator_spaces' => [ + 'operators' => ['=>' => 'align_single_space_minimal'], + ], + 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => false, + 'blank_line_before_statement' => true, + 'braces' => true, + 'cast_spaces' => [ + 'space' => 'single', + ], + 'class_attributes_separation' => true, + 'class_keyword_remove' => false, + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'combine_nested_dirname' => true, + // 'compact_nullable_typehint' => true, // PHP >= 7.1 + 'concat_space' => [ + 'spacing' => 'one', + ], + 'date_time_immutable' => false, + 'declare_equal_normalize' => true, + 'declare_strict_types' => false, // some tests need declare_strict_types === 0 + 'dir_constant' => true, + 'elseif' => true, + 'encoding' => true, + 'ereg_to_preg' => true, + 'error_suppression' => false, + 'escape_implicit_backslashes' => false, + 'explicit_indirect_variable' => true, + 'explicit_string_variable' => true, + 'final_internal_class' => true, + 'fopen_flag_order' => true, + 'fopen_flags' => true, + 'full_opening_tag' => true, + 'fully_qualified_strict_types' => true, + 'function_declaration' => true, + 'function_to_constant' => true, + 'function_typehint_space' => true, + 'general_phpdoc_annotation_remove' => [ + 'annotations' => [ + 'author', + 'package', + 'version', + ], + ], + 'heredoc_to_nowdoc' => true, + 'implode_call' => true, + 'include' => true, + 'increment_style' => true, + 'indentation_type' => true, + 'line_ending' => true, + 'linebreak_after_opening_tag' => false, + /* // Requires PHP >= 7.1 + 'list_syntax' => [ + 'syntax' => 'short', + ], + */ + 'logical_operators' => true, + 'lowercase_cast' => true, + 'lowercase_constants' => true, + 'lowercase_keywords' => true, + 'lowercase_static_reference' => true, + 'magic_constant_casing' => true, + 'magic_method_casing' => true, + 'method_argument_space' => [ + 'ensure_fully_multiline' => true, + 'keep_multiple_spaces_after_comma' => false, + ], + 'method_chaining_indentation' => true, + 'modernize_types_casting' => true, + 'multiline_comment_opening_closing' => true, + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'no_multi_line', + ], + 'native_constant_invocation' => true, + 'native_function_casing' => true, + 'native_function_invocation' => true, + 'new_with_braces' => true, + 'no_alias_functions' => true, + 'no_alternative_syntax' => true, + 'no_binary_string' => true, + 'no_blank_lines_after_class_opening' => false, + 'no_blank_lines_after_phpdoc' => true, + 'no_blank_lines_before_namespace' => false, + 'no_break_comment' => true, + 'no_closing_tag' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'no_homoglyph_names' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => [ + 'use' => 'echo', + ], + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_null_property_initialization' => true, + 'no_php4_constructor' => true, + 'no_short_bool_cast' => true, + 'no_short_echo_tag' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => true, + 'no_spaces_inside_parenthesis' => true, + 'no_superfluous_elseif' => true, + 'no_superfluous_phpdoc_tags' => false, // maybe add extra description, so keep it ... + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unneeded_curly_braces' => true, + 'no_unneeded_final_method' => true, + 'no_unreachable_default_argument_value' => false, // do not changes the logic of the code ... + 'no_unset_on_property' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'non_printable_character' => true, + 'normalize_index_brace' => true, + 'not_operator_with_space' => false, + 'not_operator_with_successor_space' => false, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => [ + 'only_untyped' => true, + ], + 'phpdoc_align' => true, + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_indent' => true, + 'phpdoc_inline_tag' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_alias_tag' => true, + 'phpdoc_no_empty_return' => false, // keep all @return php doc + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_order' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => false, + 'phpdoc_to_comment' => false, + 'phpdoc_to_return_type' => false, + 'phpdoc_trim' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_types' => true, + 'phpdoc_types_order' => [ + 'null_adjustment' => 'always_last', + 'sort_algorithm' => 'alpha', + ], + 'phpdoc_var_without_name' => true, + 'php_unit_construct' => true, + 'php_unit_dedicate_assert' => true, + 'php_unit_expectation' => true, + 'php_unit_fqcn_annotation' => true, + 'php_unit_internal_class' => true, + 'php_unit_method_casing' => true, + 'php_unit_mock' => true, + 'php_unit_namespaced' => true, + 'php_unit_no_expectation_annotation' => true, + 'php_unit_ordered_covers' => true, + 'php_unit_set_up_tear_down_visibility' => true, + 'php_unit_strict' => true, + 'php_unit_test_annotation' => true, + 'php_unit_test_case_static_method_calls' => true, + 'php_unit_test_class_requires_covers' => false, + 'pow_to_exponentiation' => true, + 'pre_increment' => true, + 'protected_to_private' => true, + 'return_assignment' => true, + 'return_type_declaration' => true, + 'self_accessor' => false, // not working as expected + 'semicolon_after_instruction' => true, + 'set_type_to_cast' => true, + 'short_scalar_cast' => true, + 'silenced_deprecation_error' => false, + 'simplified_null_return' => false, // maybe better for readability, so keep it ... + 'single_blank_line_at_eof' => true, + 'single_class_element_per_statement' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'single_line_comment_style' => [ + 'comment_types' => ['hash'], + ], + 'single_quote' => true, + 'space_after_semicolon' => true, + 'standardize_increment' => true, + 'standardize_not_equals' => true, + 'static_lambda' => true, + 'strict_comparison' => false, // TODO? do we still need "==" instead of "===" + 'strict_param' => true, + 'string_line_ending' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + 'ternary_operator_spaces' => true, + 'ternary_to_null_coalescing' => true, + 'trailing_comma_in_multiline_array' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'visibility_required' => true, + // 'void_return' => true, // PHP >= 7.1 + 'whitespace_after_comma_in_array' => true, + 'yoda_style' => [ + 'equal' => false, + 'identical' => false, + 'less_and_greater' => false, + ], + ] + ) + ->setIndent(" ") + ->setLineEnding("\n") + ->setFinder( + PhpCsFixer\Finder::create() + ->in(['src/', 'tests/']) + ->name('*.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true) + ); diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..239f4bb1 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +parameters: + level: max + checkMissingIterableValueType: false + paths: + - %currentWorkingDirectory%/src/ + ignoreErrors: diff --git a/src/EDI/Analyser.php b/src/EDI/Analyser.php index c7ddd2ff..75c4303c 100644 --- a/src/EDI/Analyser.php +++ b/src/EDI/Analyser.php @@ -10,93 +10,34 @@ */ class Analyser { - - public $segments; - private $jsonedi; - /** - * @param string $message_xml_file - * - * @return array + * @var array */ - public function loadMessageXml(string $message_xml_file): array - { - $messageXmlString = \file_get_contents($message_xml_file); - $messageXml = new \SimpleXMLIterator($messageXmlString); - unset($messageXmlString); - $message = [ - "defaults" => $this->readMessageDefaults($messageXml), - "segments" => $this->readXmlNodes($messageXml), - ]; - unset($messageXml); - - return $message; - } + public $segments; /** - * read default values in given message xml - * - * @param \SimpleXMLElement $message - * - * @return array + * @var array */ - protected function readMessageDefaults(\SimpleXMLElement $message): array - { - // init - $defaults = []; - - /* @var \SimpleXMLElement $defaultValueNode */ - foreach ($message->defaults[0] ?? [] as $defaultValueNode) { - $attributes = $defaultValueNode->attributes(); - $id = (string)$attributes->id; - $defaults[$id] = (string)$attributes->value; - } - - return $defaults; - } + private $jsonedi; /** - * read message segments and groups - * - * @param \SimpleXMLElement $element + * @param string $message_xml_file * - * @return array + * @return array|false */ - protected function readXmlNodes(\SimpleXMLElement $element): array + public function loadMessageXml(string $message_xml_file) { - $arrayElements = []; - foreach ($element as $name => $node) { - if ($name == "defaults") { - continue; - } - $arrayElement = []; - $arrayElement["type"] = $name; - $arrayElement["attributes"] = $this->readAttributesArray($node); - $details = $this->readXmlNodes($node); - if (!empty($details)) { - $arrayElement["details"] = $details; - } - $arrayElements[] = $arrayElement; + $messageXmlString = \file_get_contents($message_xml_file); + if ($messageXmlString === false) { + return false; } - return $arrayElements; - } - - /** - * return an xml elements attributes in as array - * - * @param \SimpleXMLElement $element - * - * @return array - */ - protected function readAttributesArray(\SimpleXMLElement $element): array - { - $attributes = []; - foreach ($element->attributes() as $attrName => $attr) { - $attributes[(string)$attrName] = (string)$attr; - } + $messageXml = new \SimpleXMLIterator($messageXmlString); - return $attributes; + return [ + 'defaults' => $this->readMessageDefaults($messageXml), + 'segments' => $this->readXmlNodes($messageXml), + ]; } /** @@ -104,23 +45,35 @@ protected function readAttributesArray(\SimpleXMLElement $element): array * * @param string $codesXml * - * @return array + * @return array|false */ - public function loadCodesXml(string $codesXml): array + public function loadCodesXml(string $codesXml) { $codesXmlString = \file_get_contents($codesXml); + if ($codesXmlString === false) { + return false; + } + $codesXml = new \SimpleXMLIterator($codesXmlString); - unset($codesXmlString); $codes = []; - /* @var \SimpleXmlIterator $codeCollection */ foreach ($codesXml as $codeCollection) { - $id = (string)$codeCollection->attributes()->id; + \assert($codeCollection instanceof \SimpleXMLIterator); + + $codeCollectionAttributes = $codeCollection->attributes(); + if ($codeCollectionAttributes === null) { + continue; + } + + $id = (string) $codeCollectionAttributes->id; $codes[$id] = []; - /* @var \SimpleXmlIterator $codeNode */ foreach ($codeCollection as $codeNode) { + \assert($codeNode instanceof \SimpleXMLIterator); + $codeAttributes = $codeNode->attributes(); - $code = (string)$codeAttributes->id; - $codes[$id][$code] = (string)$codeAttributes->desc; + if ($codeAttributes !== null) { + $code = (string) $codeAttributes->id; + $codes[$id][$code] = (string) $codeAttributes->desc; + } } } @@ -133,24 +86,40 @@ public function loadCodesXml(string $codesXml): array * * @param string $segment_xml_file * - * @return array + * @return array|false */ - public function loadSegmentsXml(string $segment_xml_file): array + public function loadSegmentsXml(string $segment_xml_file) { + // reset + $this->segments = []; + $segments_xml = \file_get_contents($segment_xml_file); + if ($segments_xml === false) { + return false; + } $xml = \simplexml_load_string($segments_xml); - unset($segments_xml); - $this->segments = []; + if ($xml === false) { + return false; + } + + // free memory + $segments_xml = null; - /* @var \SimpleXMLElement $segmentNode */ foreach ($xml as $segmentNode) { - $qualifier = (string)$segmentNode->attributes()->id; + \assert($segmentNode instanceof \SimpleXMLElement); + + $segmentNodeAttributes = $segmentNode->attributes(); + if ($segmentNodeAttributes === null) { + continue; + } + + $qualifier = (string) $segmentNodeAttributes->id; $segment = []; - $segment["attributes"] = $this->readAttributesArray($segmentNode); + $segment['attributes'] = $this->readAttributesArray($segmentNode); $details = $this->readXmlNodes($segmentNode); if (!empty($details)) { - $segment["details"] = $details; + $segment['details'] = $details; } $this->segments[$qualifier] = $segment; } @@ -170,7 +139,6 @@ public function process(array $data, array $rawSegments = null): string { $r = []; foreach ($data as $nrow => $segment) { - $id = $segment[0]; $r[] = ''; @@ -180,14 +148,13 @@ public function process(array $data, array $rawSegments = null): string } if (isset($this->segments[$id])) { - $attributes = $this->segments[$id]['attributes']; $details_desc = $this->segments[$id]['details']; $r[] = $id . ' - ' . $attributes['name']; - $r[] = ' (' . \wordwrap($attributes['desc'], 75, PHP_EOL . ' ') . ')'; + $r[] = ' (' . \wordwrap($attributes['desc'], 75, \PHP_EOL . ' ') . ')'; - $jsonelements = ["segmentCode" => $id]; + $jsonelements = ['segmentCode' => $id]; foreach ($segment as $idx => $detail) { $n = $idx - 1; if ($idx == 0 || !isset($details_desc[$n])) { @@ -195,7 +162,7 @@ public function process(array $data, array $rawSegments = null): string } $d_desc_attr = $details_desc[$n]['attributes']; $l1 = ' ' . $d_desc_attr['id'] . ' - ' . $d_desc_attr['name']; - $l2 = ' ' . \wordwrap($d_desc_attr['desc'], 71, PHP_EOL . ' '); + $l2 = ' ' . \wordwrap($d_desc_attr['desc'], 71, \PHP_EOL . ' '); if (\is_array($detail)) { $r[] = ' [' . $n . '] ' . \implode(',', $detail); @@ -210,7 +177,7 @@ public function process(array $data, array $rawSegments = null): string $d_sub_desc_attr = $sub_details_desc[$d_n]['attributes']; $r[] = ' [' . $d_n . '] ' . $d_detail; $r[] = ' id: ' . $d_sub_desc_attr['id'] . ' - ' . $d_sub_desc_attr['name']; - $r[] = ' ' . \wordwrap($d_sub_desc_attr['desc'], 69, PHP_EOL . ' '); + $r[] = ' ' . \wordwrap($d_sub_desc_attr['desc'], 69, \PHP_EOL . ' '); $r[] = ' type: ' . $d_sub_desc_attr['type']; $jsoncomposite[$d_sub_desc_attr['name']] = $d_detail; @@ -224,7 +191,7 @@ public function process(array $data, array $rawSegments = null): string $r[] = ' length: ' . $d_sub_desc_attr['length']; } - //check for skipped data + // check for skipped data unset( $d_sub_desc_attr['id'], $d_sub_desc_attr['name'], @@ -239,8 +206,7 @@ public function process(array $data, array $rawSegments = null): string if (!empty($d_sub_desc_attr)) { var_dump($d_sub_desc_attr); } - */ - + */ } } $jsonelements[$d_desc_attr['name']] = $jsoncomposite; @@ -254,21 +220,87 @@ public function process(array $data, array $rawSegments = null): string $jsonsegment[$attributes['name']] = $jsonelements; } else { $r[] = $id; - $jsonsegment["UnrecognisedType"] = $segment; + $jsonsegment['UnrecognisedType'] = $segment; } $this->jsonedi[] = $jsonsegment; } - return \implode(PHP_EOL, $r); + return \implode(\PHP_EOL, $r); } /** * return the processed EDI in json format * - * @return string json + * @return false|string */ - public function getJson(): string + public function getJson() { return \json_encode($this->jsonedi); } + + /** + * read default values in given message xml + * + * @param \SimpleXMLElement $message + * + * @return array + */ + protected function readMessageDefaults(\SimpleXMLElement $message): array + { + // init + $defaults = []; + + /* @var \SimpleXMLElement $defaultValueNode */ + foreach ($message->defaults[0] ?? [] as $defaultValueNode) { + $attributes = $defaultValueNode->attributes(); + $id = (string) $attributes->id; + $defaults[$id] = (string) $attributes->value; + } + + return $defaults; + } + + /** + * read message segments and groups + * + * @param \SimpleXMLElement $element + * + * @return array + */ + protected function readXmlNodes(\SimpleXMLElement $element): array + { + $arrayElements = []; + foreach ($element as $name => $node) { + if ($name == 'defaults') { + continue; + } + $arrayElement = []; + $arrayElement['type'] = $name; + $arrayElement['attributes'] = $this->readAttributesArray($node); + $details = $this->readXmlNodes($node); + if (!empty($details)) { + $arrayElement['details'] = $details; + } + $arrayElements[] = $arrayElement; + } + + return $arrayElements; + } + + /** + * return an xml elements attributes in as array + * + * @param \SimpleXMLElement $element + * + * @return array + */ + protected function readAttributesArray(\SimpleXMLElement $element): array + { + $attributes = []; + foreach ($element->attributes() ?? [] as $attrName => $attr) { + $attributes[(string) $attrName] = (string) $attr; + } + + return $attributes; + } } diff --git a/src/EDI/Encoder.php b/src/EDI/Encoder.php index aeb2391d..275e2e14 100644 --- a/src/EDI/Encoder.php +++ b/src/EDI/Encoder.php @@ -63,7 +63,7 @@ class Encoder /** * Encoder constructor. * - * @param null|array $array + * @param array|null $array * @param bool $wrap */ public function __construct($array = null, $wrap = true) @@ -93,7 +93,7 @@ public function encode(array $array, $wrap = true, $filterKeys = false): string $count = \count($array); $k = 0; foreach ($array as $row) { - $k++; + ++$k; if ($filterKeys) { unset($row['segmentIdx']); } @@ -119,14 +119,18 @@ public function encodeSegment(array $row): string $str = ''; $t = \count($row); + /** @noinspection AlterInForeachInspection */ foreach ($row as $i => &$iValue) { if (\is_array($iValue)) { - if (\count($iValue) === 1 - && \is_array(\reset($iValue)) + if ( + \count($iValue) === 1 + && + \is_array(\reset($iValue)) ) { $iValue = \array_pop($iValue); } + /** @noinspection NotOptimalIfConditionsInspection */ if (\is_array($iValue)) { foreach ($iValue as &$temp) { $temp = $this->escapeValue($temp); @@ -145,43 +149,19 @@ public function encodeSegment(array $row): string } $str .= $this->sepData; } - unset($iValue); $str .= $this->symbEnd; return $str; } - /** - * @param string|int $str - * - * @return string - */ - private function escapeValue(&$str): string - { - $search = [ - $this->symbRel, - $this->sepComp, - $this->sepData, - $this->symbEnd, - ]; - $replace = [ - $this->symbRel . $this->symbRel, - $this->symbRel . $this->sepComp, - $this->symbRel . $this->sepData, - $this->symbRel . $this->symbEnd, - ]; - - return \str_replace($search, $replace, $str); - } - /** * @return string */ public function get(): string { if ($this->UNAActive) { - $una = "UNA" . $this->sepComp . + $una = 'UNA' . $this->sepComp . $this->sepData . $this->sepDec . $this->symbRel . @@ -205,9 +185,7 @@ public function get(): string */ public function setUNA(string $chars, bool $user_call = true): bool { - if (\is_string($chars) - && \strlen($chars) == 6 - ) { + if (\strlen($chars) == 6) { $this->sepComp = $chars[0]; $this->sepData = $chars[1]; $this->sepDec = $chars[2]; @@ -244,4 +222,27 @@ public function disableUNA() { $this->UNAActive = false; } + + /** + * @param int|string $str + * + * @return string + */ + private function escapeValue(&$str): string + { + $search = [ + $this->symbRel, + $this->sepComp, + $this->sepData, + $this->symbEnd, + ]; + $replace = [ + $this->symbRel . $this->symbRel, + $this->symbRel . $this->sepComp, + $this->symbRel . $this->sepData, + $this->symbRel . $this->symbEnd, + ]; + + return \str_replace($search, $replace, (string) $str); + } } diff --git a/src/EDI/Interpreter.php b/src/EDI/Interpreter.php index 107264f2..07f6d451 100644 --- a/src/EDI/Interpreter.php +++ b/src/EDI/Interpreter.php @@ -13,72 +13,71 @@ class Interpreter { /** - * @var \SimpleXMLElement + * @var array */ - private $xmlMsg; + public $messageTextConf = [ + 'MISSINGREQUIREDSEGMENT' => 'Missing required segment', + 'MISSINGREQUIREDGROUP' => 'Missing required group', + 'NOTCONFORMANT' => "It looks like that this message isn't conformant to the mapping provided. (Not all segments were added)", + 'TOOMANYELEMENTS_COMPOSITE' => 'This composite data element has more elements than expected', + 'TOOMANYELEMENTS' => 'This segment has more data elements than expected', + 'MISSINGINTERCHANGEDELIMITER' => 'The file has at least one UNB or UNZ missing', + 'MISSINGMESSAGEDELIMITER' => 'The message has at least one UNH or UNT missing', + ]; /** * @var array */ - private $xmlSeg; + public $segmentTemplates = [ + 'DTM' => ['DTM', '999', 'XXX'], + ]; /** - * @var string + * @var array */ - private $xmlSvc; + public $groupTemplates = [ + 'SG1' => [['TDT', '20', 'XXX']], + ]; /** - * @var array + * @var \SimpleXMLElement */ - private $ediGroups; + private $xmlMsg; /** * @var array */ - private $errors; + private $xmlSeg; /** * @var array */ - private $msgs; + private $xmlSvc; /** * @var array */ - private $serviceSeg; + private $ediGroups; /** - * @var \Closure + * @var array */ - private $comparisonFunction; + private $errors; /** * @var array */ - public $messageTextConf = [ - 'MISSINGREQUIREDSEGMENT' => "Missing required segment", - 'MISSINGREQUIREDGROUP' => "Missing required group", - 'NOTCONFORMANT' => "It looks like that this message isn't conformant to the mapping provided. (Not all segments were added)", - 'TOOMANYELEMENTS_COMPOSITE' => "This composite data element has more elements than expected", - 'TOOMANYELEMENTS' => "This segment has more data elements than expected", - 'MISSINGINTERCHANGEDELIMITER' => "The file has at least one UNB or UNZ missing", - 'MISSINGMESSAGEDELIMITER' => "The message has at least one UNH or UNT missing", - ]; + private $msgs; /** * @var array */ - public $segmentTemplates = [ - 'DTM' => ['DTM', '999', 'XXX'], - ]; + private $serviceSeg; /** - * @var array + * @var callable */ - public $groupTemplates = [ - 'SG1' => - [['TDT', '20', 'XXX']], - ]; + private $comparisonFunction; /** * Split multiple messages and process @@ -86,11 +85,22 @@ class Interpreter * @param string $xmlMsg Path to XML Message representation * @param array $xmlSeg Segments processed by EDI\Analyser::loadSegmentsXml * @param array $xmlSvc Service segments processed by EDI\Analyser::loadSegmentsXml - * @param null|array $messageTextConf Personalisation of error messages + * @param array|null $messageTextConf Personalisation of error messages */ public function __construct(string $xmlMsg, array $xmlSeg, array $xmlSvc, array $messageTextConf = null) { - $this->xmlMsg = \simplexml_load_file($xmlMsg); + // simplexml_load_file: This can be affected by a PHP bug #62577 (https://bugs.php.net/bug.php?id=62577) + $xmlData = \file_get_contents($xmlMsg); + if ($xmlData === false) { + throw new \InvalidArgumentException('file_get_contents for "' . $xmlMsg . '" faild'); + } + + $xmlMsgTmp = \simplexml_load_string($xmlData); + if ($xmlMsgTmp === false) { + throw new \InvalidArgumentException('simplexml_load_string for "' . $xmlMsg . '" faild'); + } + + $this->xmlMsg = $xmlMsgTmp; $this->xmlSeg = $xmlSeg; $this->xmlSvc = $xmlSvc; if ($messageTextConf !== null) { @@ -98,7 +108,7 @@ public function __construct(string $xmlMsg, array $xmlSeg, array $xmlSvc, array } $this->errors = []; - $this->comparisonFunction = function ($segment, $elm) { + $this->comparisonFunction = static function ($segment, $elm) { return $segment[0] == $elm['id']; }; } @@ -177,6 +187,88 @@ public function prepare(array $parsed): array return $groups; } + /** + * Get result as json. + * + * @param bool $pretty + * + * @return false|string + */ + public function getJson(bool $pretty = false) + { + if ($pretty) { + return \json_encode($this->ediGroups, \JSON_PRETTY_PRINT); + } + + return \json_encode($this->ediGroups); + } + + /** + * Get result as Arrayy Object. + * + * @return Arrayy + */ + public function getArrayy() + { + return new Arrayy($this->ediGroups); + } + + /** + * Get errors + * + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } + + /** + * Get splitted messages. + * + * @return array + */ + public function getMessages(): array + { + return $this->msgs; + } + + /** + * Get service segments. + * + * @return array + */ + public function getServiceSegments() + { + return $this->serviceSeg; + } + + /** + * Get json service segments. + * + * @param bool $pretty + * + * @return false|string + */ + public function getJsonServiceSegments(bool $pretty = false) + { + if ($pretty) { + return \json_encode($this->serviceSeg, \JSON_PRETTY_PRINT); + } + + return \json_encode($this->serviceSeg); + } + + /** + * Get service segments as Arrayy Object. + * + * @return Arrayy + */ + public function getArrayyServiceSegments() + { + return new Arrayy($this->serviceSeg); + } + /** * Split multiple messages * @@ -198,60 +290,65 @@ private function splitMessages(&$parsed, &$errors): array switch ($segment[0]) { case 'UNB': $hasInterchangeDelimiters = 0; - $hasInterchangeDelimiters++; + ++$hasInterchangeDelimiters; $service['UNB'] = $segment; + break; case 'UNZ': $hasInterchangeDelimiters--; if ($hasInterchangeDelimiters != 0) { - $sid = ($hasInterchangeDelimiters < 0) ? "UNB" : "UNZ"; + $sid = ($hasInterchangeDelimiters < 0) ? 'UNB' : 'UNZ'; $errors[] = [ - "text" => $this->messageTextConf['MISSINGINTERCHANGEDELIMITER'], - "position" => $c, - "segmentId" => $sid, + 'text' => $this->messageTextConf['MISSINGINTERCHANGEDELIMITER'], + 'position' => $c, + 'segmentId' => $sid, ]; } $service['UNZ'] = $segment; + break; case 'UNH': $hasMessageDelimiters = 0; - $hasMessageDelimiters++; + ++$hasMessageDelimiters; $tmpmsg = [$segment]; + break; case 'UNT': $hasMessageDelimiters--; $tmpmsg[] = $segment; $messages[] = $tmpmsg; if ($hasMessageDelimiters != 0) { - $sid = ($hasMessageDelimiters < 0) ? "UNH" : "UNT"; + $sid = ($hasMessageDelimiters < 0) ? 'UNH' : 'UNT'; $errors[] = [ - "text" => $this->messageTextConf['MISSINGMESSAGEDELIMITER'], - "position" => $c, - "segmentId" => $sid, + 'text' => $this->messageTextConf['MISSINGMESSAGEDELIMITER'], + 'position' => $c, + 'segmentId' => $sid, ]; } + break; default: $tmpmsg[] = $segment; + break; } } if ($hasInterchangeDelimiters != 0) { - $sid = ($hasInterchangeDelimiters < 0) ? "UNB" : "UNZ"; + $sid = ($hasInterchangeDelimiters < 0) ? 'UNB' : 'UNZ'; $errors[] = [ - "text" => $this->messageTextConf['MISSINGINTERCHANGEDELIMITER'], - "position" => $c ?? '', - "segmentId" => $sid, + 'text' => $this->messageTextConf['MISSINGINTERCHANGEDELIMITER'], + 'position' => $c ?? '', + 'segmentId' => $sid, ]; } if ($hasMessageDelimiters != 0) { - $sid = ($hasMessageDelimiters < 0) ? "UNH" : "UNT"; + $sid = ($hasMessageDelimiters < 0) ? 'UNH' : 'UNT'; $errors[] = [ - "text" => $this->messageTextConf['MISSINGMESSAGEDELIMITER'], - "position" => $c ?? '', - "segmentId" => $sid, + 'text' => $this->messageTextConf['MISSINGMESSAGEDELIMITER'], + 'position' => $c ?? '', + 'segmentId' => $sid, ]; } @@ -276,16 +373,16 @@ private function loopMessage(array &$message, \SimpleXMLElement $xml, array &$er $segmentIdx = 0; foreach ($xml->children() as $elm) { - if ($elm->getName() == "group") { + if ($elm->getName() == 'group') { $this->processXmlGroup($elm, $message, $segmentIdx, $groupedEdi, $errors); - } elseif ($elm->getName() == "segment") { + } elseif ($elm->getName() == 'segment') { $this->processXmlSegment($elm, $message, $segmentIdx, $groupedEdi, $errors); } } if ($segmentIdx != \count($message)) { $errors[] = [ - "text" => $this->messageTextConf['NOTCONFORMANT'], + 'text' => $this->messageTextConf['NOTCONFORMANT'], ]; } @@ -309,7 +406,7 @@ private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$ $groupVisited = false; $newGroup = []; - for ($g = 0; $g < $elm['maxrepeat']; $g++) { + for ($g = 0; $g < $elm['maxrepeat']; ++$g) { $grouptemp = []; if ($message[$segmentIdx][0] != $elm->children()[0]['id']) { if ( @@ -325,9 +422,9 @@ private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$ } $errors[] = [ - "text" => $this->messageTextConf['MISSINGREQUIREDGROUP'] . " " . ($fixed ? '(patched)' : ''), - "position" => $segmentIdx, - "segmentId" => $elmType, + 'text' => $this->messageTextConf['MISSINGREQUIREDGROUP'] . ' ' . ($fixed ? '(patched)' : ''), + 'position' => $segmentIdx, + 'segmentId' => $elmType, ]; } else { break; @@ -335,7 +432,7 @@ private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$ } foreach ($elm->children() as $elm2) { - if ($elm2->getName() == "group") { + if ($elm2->getName() == 'group') { $this->processXmlGroup($elm2, $message, $segmentIdx, $grouptemp, $errors); } else { $this->processXmlSegment($elm2, $message, $segmentIdx, $grouptemp, $errors); @@ -344,7 +441,6 @@ private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$ } $newGroup[] = $grouptemp; - } if (\count($newGroup) === 0) { @@ -370,24 +466,20 @@ private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int // init $segmentVisited = false; - for ($i = 0; $i < $elm['maxrepeat']; $i++) { - + for ($i = 0; $i < $elm['maxrepeat']; ++$i) { if (\call_user_func($this->comparisonFunction, $message[$segmentIdx], $elm)) { - $jsonMessage = $this->processSegment($message[$segmentIdx], $this->xmlSeg, $segmentIdx, $errors); $segmentVisited = true; $this->doAddArray($array, $jsonMessage); - $segmentIdx++; - + ++$segmentIdx; } else { - if (!$segmentVisited && isset($elm['required'])) { $fixed = false; if ($elm['replacewith'] !== null) { - $elmType = (string)$elm['replacewith']; + $elmType = (string) $elm['replacewith']; } else { - $elmType = (string)$elm['id']; + $elmType = (string) $elm['id']; } if (isset($this->segmentTemplates[$elmType])) { @@ -397,9 +489,9 @@ private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int } $errors[] = [ - "text" => $this->messageTextConf['MISSINGREQUIREDSEGMENT'] . " " . ($fixed ? '(patched)' : ''), - "position" => $segmentIdx, - "segmentId" => (string)$elm['id'], + 'text' => $this->messageTextConf['MISSINGREQUIREDSEGMENT'] . ' ' . ($fixed ? '(patched)' : ''), + 'position' => $segmentIdx, + 'segmentId' => (string) $elm['id'], ]; } @@ -439,8 +531,8 @@ private function doAddArray(array &$array, array &$jsonMessage) * * @param array $segment * @param array $xmlMap - * @param null|int $segmentIdx - * @param null|array $errors + * @param int|null $segmentIdx + * @param array|null $errors * * @return array */ @@ -453,7 +545,7 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ar $attributes = $xmlMap[$id]['attributes']; $details_desc = $xmlMap[$id]['details']; - $jsonelements = ["segmentIdx" => $segmentIdx, "segmentCode" => $id]; + $jsonelements = ['segmentIdx' => $segmentIdx, 'segmentCode' => $id]; foreach ($segment as $idx => $detail) { $n = $idx - 1; if ($idx == 0) { @@ -462,11 +554,12 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ar if (!isset($details_desc[$n])) { $errors[] = [ - "text" => $this->messageTextConf['TOOMANYELEMENTS'], - "position" => $segmentIdx, - "segmentId" => $id, + 'text' => $this->messageTextConf['TOOMANYELEMENTS'], + 'position' => $segmentIdx, + 'segmentId' => $id, ]; - $jsonelements["Extension" . $n] = $detail; + $jsonelements['Extension' . $n] = $detail; + continue; } @@ -483,11 +576,11 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ar foreach ($detail as $d_n => $d_detail) { if (!isset($sub_details_desc[$d_n])) { $errors[] = [ - "text" => $this->messageTextConf['TOOMANYELEMENTS_COMPOSITE'], - "position" => $segmentIdx . "/" . $idx, - "segmentId" => $id, + 'text' => $this->messageTextConf['TOOMANYELEMENTS_COMPOSITE'], + 'position' => $segmentIdx . '/' . $idx, + 'segmentId' => $id, ]; - $jsoncomposite["CompositeExtension" . $d_n] = $d_detail; + $jsoncomposite['CompositeExtension' . $d_n] = $d_detail; continue; } @@ -517,11 +610,9 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ar } else { $jsonelements[$d_desc_attr['name']] = $jsoncomposite; } - } $jsonsegment['key'] = $attributes['name']; $jsonsegment['value'] = $jsonelements; - } elseif ($xmlMap !== $this->xmlSvc) { $jsonsegment = $this->processSegment($segment, $this->xmlSvc, $segmentIdx, $errors); } else { @@ -551,86 +642,4 @@ private function processService(array &$segments): array return $processed; } - - /** - * Get result as json. - * - * @param bool $pretty - * - * @return false|string - */ - public function getJson(bool $pretty = false) - { - if ($pretty) { - return \json_encode($this->ediGroups, JSON_PRETTY_PRINT); - } - - return \json_encode($this->ediGroups); - } - - /** - * Get result as Arrayy Object. - * - * @return Arrayy - */ - public function getArrayy() - { - return new Arrayy($this->ediGroups); - } - - /** - * Get errors - * - * @return array - */ - public function getErrors(): array - { - return $this->errors; - } - - /** - * Get splitted messages. - * - * @return array - */ - public function getMessages(): array - { - return $this->msgs; - } - - /** - * Get service segments. - * - * @return array - */ - public function getServiceSegments() - { - return $this->serviceSeg; - } - - /** - * Get json service segments. - * - * @param bool $pretty - * - * @return false|string - */ - public function getJsonServiceSegments(bool $pretty = false) - { - if ($pretty) { - return \json_encode($this->serviceSeg, JSON_PRETTY_PRINT); - } - - return \json_encode($this->serviceSeg); - } - - /** - * Get service segments as Arrayy Object. - * - * @return Arrayy - */ - public function getArrayyServiceSegments() - { - return new Arrayy($this->serviceSeg); - } } diff --git a/src/EDI/Parser.php b/src/EDI/Parser.php index fa2c17f0..0bcfadf5 100644 --- a/src/EDI/Parser.php +++ b/src/EDI/Parser.php @@ -33,60 +33,60 @@ class Parser /** * @var string */ - private static $DELIMITER = "/"; + private static $DELIMITER = '/'; /** - * @var null|string : component separator character (default \:) + * @var string|null : component separator character (default \:) */ private $sepComp; /** - * @var null|string : component separator character (default :) + * @var string|null : component separator character (default :) */ private $sepUnescapedComp; /** - * @var null|string : data separator character (default \+) + * @var string|null : data separator character (default \+) */ private $sepData; /** - * @var null|string : dec separator character (no use but here) (default .) + * @var string|null : dec separator character (no use but here) (default .) */ private $sepDec; /** - * @var null|string : release character (default \?) + * @var string|null : release character (default \?) */ private $symbRel; /** - * @var null|string (default ?) + * @var string|null (default ?) */ private $symbUnescapedRel; /** - * @var null|string : repetition character (no use but here) (default *) + * @var string|null : repetition character (no use but here) (default *) */ private $symbRep; /** - * @var null|string : end character (default ') + * @var string|null : end character (default ') */ private $symbEnd; /** - * @var null|string : safe string (default §SS§) + * @var string|null : safe string (default §SS§) */ private $stringSafe; /** - * @var null|string : encoding (default UNOB) + * @var string|null : encoding (default UNOB) */ private $encoding; /** - * @var null|string : message format from UNH + * @var string|null : message format from UNH */ private $messageFormat; @@ -95,10 +95,13 @@ class Parser */ private $messageDirectory; + /** + * @var array + */ private static $encodingToStripChars = [ - "UNOA" => "/[\x01-\x1F\x80-\xFF]/", // not as restrictive as it should be - "UNOB" => "/[\x01-\x1F\x80-\xFF]/", - "UNOC" => "/[\x01-\x1F\x7F-\x9F]/", + 'UNOA' => "/[\x01-\x1F\x80-\xFF]/", // not as restrictive as it should be + 'UNOB' => "/[\x01-\x1F\x80-\xFF]/", + 'UNOC' => "/[\x01-\x1F\x7F-\x9F]/", ]; /** @@ -114,7 +117,7 @@ class Parser /** * Parser constructor. * - * @param null|string|string[] $url + * @param string|string[]|null $url */ public function __construct($url = null) { @@ -144,15 +147,13 @@ public function __construct($url = null) $this->rawSegments = $url; /** @noinspection UnusedFunctionResultInspection */ $this->parse($url); - - } elseif (file_exists($url)) { + } elseif (\file_exists($url)) { // // Object constructed with a path to a file as argument // /** @noinspection UnusedFunctionResultInspection */ $this->load($url); - } else { // @@ -160,7 +161,6 @@ public function __construct($url = null) // /** @noinspection UnusedFunctionResultInspection */ $this->loadString($url); - } } @@ -178,15 +178,15 @@ public function parse(array &$file2): array ++$i; // Null byte and carriage return removal. (CR+LF) - $line = str_replace(["\x00", "\r", "\n"], '', $line); + $line = \str_replace(["\x00", "\r", "\n"], '', $line); // Basic sanitization, remove non printable chars. $lineTrim = \trim($line); - $line = \preg_replace($this->stripChars, '', $lineTrim); + $line = (string) \preg_replace($this->stripChars, '', $lineTrim); $line_bytes = \strlen($line); if ($line_bytes !== \strlen($lineTrim)) { - $this->errors[] = "There's a not printable character on line " . $i . ": " . $lineTrim; + $this->errors[] = "There's a not printable character on line " . $i . ': ' . $lineTrim; } if ($line_bytes < 2) { @@ -194,26 +194,30 @@ public function parse(array &$file2): array } switch (\substr($line, 0, 3)) { - case "UNA": + case 'UNA': if (!$this->unaChecked) { $this->analyseUNA(\substr($line, 4, 6)); } + break; - case "UNB": + case 'UNB': $line = $this->splitSegment($line); if (!$this->unbChecked) { $this->analyseUNB($line[1]); } $this->parsedfile[] = $line; + break; - case "UNH": + case 'UNH': $line = $this->splitSegment($line); $this->analyseUNH($line); $this->parsedfile[] = $line; + break; default: $line = $this->splitSegment($line); $this->parsedfile[] = $line; + break; } } @@ -221,36 +225,6 @@ public function parse(array &$file2): array return $this->parsedfile; } - /** - * Reset UNA's characters definition - * - * @return void - */ - private function resetUNA() - { - $this->sepComp = "\:"; - $this->sepUnescapedComp = ":"; - $this->sepData = "\+"; - $this->sepDec = "."; // See later if a preg_quote is needed - $this->symbRel = "\?"; - $this->symbUnescapedRel = "?"; - $this->symbRep = "*"; // See later if a preg_quote is needed - $this->symbEnd = "'"; - $this->stringSafe = "§SS§"; - $this->unaChecked = false; - } - - /** - * Reset UNB's encoding definition - * - * @return void - */ - private function resetUNB() - { - $this->encoding = "UNOB"; - $this->unbChecked = false; - } - /** * Read UNA's characters definition * @@ -312,7 +286,7 @@ public function analyseUNB($encoding) /** * Identify message type * - * @param string[] $line UNH segment + * @param array $line UNH segment * * @return void */ @@ -333,6 +307,127 @@ public function analyseUNH(array $line) $this->messageDirectory = $lineElement[2]; } + /** + * Get errors + * + * @return array + */ + public function errors(): array + { + return $this->errors; + } + + /** + * Get result + * + * @return array + */ + public function get(): array + { + return $this->parsedfile; + } + + /** + * Get raw segments array + * + * @return array|string[]|null + */ + public function getRawSegments() + { + return $this->rawSegments; + } + + /** + * Load the message from file. + * + * @param string $url + * + * @return array|false + */ + public function load($url) + { + $file = \file_get_contents($url); + if ($file === false) { + return false; + } + + return $this->loadString($file); + } + + /** + * Load the message from a string. + * + * @param string $string + * + * @return array + */ + public function loadString(&$string): array + { + /** @noinspection CallableParameterUseCaseInTypeContextInspection */ + $string = $this->unwrap($string); + $this->rawSegments = $string; + + return $this->parse($string); + } + + /** + * Change the default regex used for stripping invalid characters. + * + * @param string $regex + * + * @return void + */ + public function setStripRegex($regex) + { + $this->stripChars = $regex; + } + + /** + * @return string|null + */ + public function getMessageFormat() + { + return $this->messageFormat; + } + + /** + * @return string|null + */ + public function getMessageDirectory() + { + return $this->messageDirectory; + } + + /** + * Reset UNA's characters definition + * + * @return void + */ + private function resetUNA() + { + $this->sepComp = "\:"; + $this->sepUnescapedComp = ':'; + $this->sepData = "\+"; + $this->sepDec = '.'; // See later if a preg_quote is needed + $this->symbRel = "\?"; + $this->symbUnescapedRel = '?'; + $this->symbRep = '*'; // See later if a preg_quote is needed + $this->symbEnd = "'"; + $this->stringSafe = '§SS§'; + $this->unaChecked = false; + } + + /** + * Reset UNB's encoding definition + * + * @return void + */ + private function resetUNB() + { + $this->encoding = 'UNOB'; + $this->unbChecked = false; + } + /** * Unwrap string splitting rows on terminator (if not escaped) * @@ -358,7 +453,7 @@ private function unwrap(string &$string): array \strpos($string, 'UNB') === 0 ) { $this->analyseUNB( - \preg_replace( + (string) \preg_replace( "#^UNB\+#", '', \substr($string, 0, 8) @@ -366,14 +461,14 @@ private function unwrap(string &$string): array ); } - $string = \preg_replace( - "/(([^" . $this->symbRel . "]" . $this->symbRel . "{2})+|[^" . $this->symbRel . "])" . $this->symbEnd . "/", - "$1" . $this->stringSafe, + $string = (string) \preg_replace( + '/(([^' . $this->symbRel . ']' . $this->symbRel . '{2})+|[^' . $this->symbRel . '])' . $this->symbEnd . '/', + '$1' . $this->stringSafe, $string ); $file = \preg_split( - self::$DELIMITER . $this->stringSafe . self::$DELIMITER . "i", + self::$DELIMITER . $this->stringSafe . self::$DELIMITER . 'i', $string ); // fallback @@ -381,7 +476,7 @@ private function unwrap(string &$string): array $file = []; } - $end = \stripslashes($this->symbEnd); + $end = \stripslashes($this->symbEnd . ''); foreach ($file as $fc => &$line) { if (\trim($line) == '') { /* @noinspection OffsetOperationsInspection */ @@ -404,7 +499,7 @@ private function splitSegment(string &$str): array { // remove ending "symbEnd" $str = \trim( - \preg_replace( + (string) \preg_replace( self::$DELIMITER . $this->symbEnd . '$' . self::$DELIMITER, '', $str @@ -413,14 +508,14 @@ private function splitSegment(string &$str): array // replace duplicate "symbRel" $str = \str_replace( - $this->symbUnescapedRel . $this->symbUnescapedRel, - $this->stringSafe, + $this->symbUnescapedRel . $this->symbUnescapedRel . '', + $this->stringSafe ?? '', $str ); // split on "sepData" if not escaped (negative lookbehind) $matches = \preg_split( - self::$DELIMITER . "(?symbRel . ")" . $this->sepData . self::$DELIMITER, + self::$DELIMITER . '(?symbRel . ')' . $this->sepData . self::$DELIMITER, $str ); // fallback @@ -441,22 +536,29 @@ private function splitSegment(string &$str): array // // Question mark is represented by ?? - if (\strpos($value, $this->symbEnd) !== false) { - if (\preg_match(self::$DELIMITER . "(?symbRel . ")" . $this->symbEnd . self::$DELIMITER, $value)) { - $this->errors[] = "There's a " . \stripslashes($this->symbEnd) . " not escaped in the data; string " . $str; + if ( + $this->symbEnd + && + \strpos($value, $this->symbEnd) !== false + ) { + if (\preg_match(self::$DELIMITER . '(?symbRel . ')' . $this->symbEnd . self::$DELIMITER, $value)) { + $this->errors[] = "There's a " . \stripslashes($this->symbEnd) . ' not escaped in the data; string ' . $str; } } - if (\strpos($value, $this->symbUnescapedRel) !== false) { - if (\preg_match(self::$DELIMITER . "(?symbRel . ")" . $this->symbRel . "(?!" . $this->symbRel . ")(?!" . $this->sepData . ")(?!" . $this->sepComp . ")(?!" . $this->symbEnd . ")" . self::$DELIMITER, $value)) { - $this->errors[] = "There's a character not escaped with " . \stripslashes($this->symbRel) . " in the data; string " . $value; + if ( + $this->symbUnescapedRel + && + \strpos($value, $this->symbUnescapedRel) !== false + ) { + if (\preg_match(self::$DELIMITER . '(?symbRel . ')' . $this->symbRel . '(?!' . $this->symbRel . ')(?!' . $this->sepData . ')(?!' . $this->sepComp . ')(?!' . $this->symbEnd . ')' . self::$DELIMITER, $value)) { + $this->errors[] = "There's a character not escaped with " . \stripslashes($this->symbRel ?? '') . ' in the data; string ' . $value; } } // split on "sepComp" $value = $this->splitData($value); } - unset($value); return $matches; } @@ -475,30 +577,29 @@ private function splitData(string &$str) } $replace = function (&$string) { - - if (\strpos($string, $this->symbUnescapedRel) !== false) { + if ($this->symbUnescapedRel && \strpos($string, $this->symbUnescapedRel) !== false) { $string = \preg_replace( - self::$DELIMITER . $this->symbRel . "(?=" . $this->symbRel . ")|" . $this->symbRel . "(?=" . $this->sepData . ")|" . $this->symbRel . "(?=" . $this->sepComp . ")|" . $this->symbRel . "(?=" . $this->symbEnd . ")" . self::$DELIMITER, + self::$DELIMITER . $this->symbRel . '(?=' . $this->symbRel . ')|' . $this->symbRel . '(?=' . $this->sepData . ')|' . $this->symbRel . '(?=' . $this->sepComp . ')|' . $this->symbRel . '(?=' . $this->symbEnd . ')' . self::$DELIMITER, '', $string ); } return \str_replace( - $this->stringSafe, - $this->symbUnescapedRel, + $this->stringSafe ?? '', + $this->symbUnescapedRel ?? '', $string ); }; // check for "sepUnescapedComp" in the string - if (\strpos($str, $this->sepUnescapedComp) === false) { + if ($this->sepUnescapedComp && \strpos($str, $this->sepUnescapedComp) === false) { return $replace($str); } // split on "sepComp" if not escaped (negative lookbehind) $array = \preg_split( - self::$DELIMITER . "(?symbRel . ")" . $this->sepComp . self::$DELIMITER, + self::$DELIMITER . '(?symbRel . ')' . $this->sepComp . self::$DELIMITER, $str ); // fallback @@ -516,90 +617,4 @@ private function splitData(string &$str) return $array; } - - /** - * Get errors - * - * @return array - */ - public function errors(): array - { - return $this->errors; - } - - /** - * Get result - * - * @return array - */ - public function get(): array - { - return $this->parsedfile; - } - - /** - * Get raw segments array - * - * @return array|string[]|null - */ - public function getRawSegments() - { - return $this->rawSegments; - } - - /** - * Load the message from file. - * - * @param string $url - * - * @return array - */ - public function load($url): array - { - $file = \file_get_contents($url); - - return $this->loadString($file); - } - - /** - * Load the message from a string. - * - * @param string $string - * - * @return array - */ - public function loadString(&$string): array - { - /** @noinspection CallableParameterUseCaseInTypeContextInspection */ - $string = $this->unwrap($string); - $this->rawSegments = $string; - - return $this->parse($string); - } - - /** - * Change the default regex used for stripping invalid characters. - * - * @param string $regex - */ - public function setStripRegex($regex) - { - $this->stripChars = $regex; - } - - /** - * @return string|null - */ - public function getMessageFormat() - { - return $this->messageFormat; - } - - /** - * @return null|string - */ - public function getMessageDirectory() - { - return $this->messageDirectory; - } } diff --git a/src/EDI/Reader.php b/src/EDI/Reader.php index 29e43731..bab08ff4 100644 --- a/src/EDI/Reader.php +++ b/src/EDI/Reader.php @@ -10,14 +10,13 @@ */ class Reader { - /** * @var array parsed EDI file */ private $parsedfile; /** - * @var array + * @var array */ private $errors = []; @@ -35,6 +34,8 @@ public function __construct(string $url = null) /** * Get errors + * + * @return array */ public function errors(): array { @@ -43,6 +44,8 @@ public function errors(): array /** * reset errors + * + * @return void */ public function resetErrors() { @@ -99,7 +102,15 @@ public function preValidate(): bool } $r = $this->readUNHmessageNumber(); - if (!$r && isset($this->errors[0]) && $this->errors[0] == 'Segment "UNH" is ambiguous') { + if ( + !$r + && + ( + $this->errors !== [] + && + $this->errors[0] == 'Segment "UNH" is ambiguous' + ) + ) { $this->errors = []; $this->errors[] = 'File has multiple messages'; @@ -114,7 +125,7 @@ public function preValidate(): bool * * @param string $ediMessage * - * @return array + * @return array */ public static function splitMultiMessage(string $ediMessage): array { @@ -125,9 +136,9 @@ public static function splitMultiMessage(string $ediMessage): array $segment = ''; foreach (self::unwrap($ediMessage) as $segment) { - if (\strpos($segment, 'UNB') === 0) { $unb = $segment; + continue; } @@ -136,6 +147,7 @@ public static function splitMultiMessage(string $ediMessage): array $message[] = $unb; } $message[] = $segment; + continue; } @@ -143,6 +155,7 @@ public static function splitMultiMessage(string $ediMessage): array $message[] = $segment; $splicedMessages[] = $message; $message = []; + continue; } @@ -159,40 +172,22 @@ public static function splitMultiMessage(string $ediMessage): array } foreach ($splicedMessages as $k => &$message) { - $message = \implode(PHP_EOL, $splicedMessages[$k]); + $message = \implode(\PHP_EOL, $splicedMessages[$k]); } return $splicedMessages; } - /** - * unwrap string splitting rows on terminator (if not escaped) - * - * @param string $string - * - * @return \Generator - */ - private static function unwrap($string) - { - foreach (\preg_split("/(?|string $filter segment filter by segment name and values + * @param int $l1 + * @param false|int $l2 * - * @return string + * @return string|null */ - public function readEdiDataValueReq($filter, int $l1, $l2 = false): string + public function readEdiDataValueReq($filter, int $l1, $l2 = false) { return $this->readEdiDataValue($filter, $l1, $l2, true); } @@ -200,15 +195,15 @@ public function readEdiDataValueReq($filter, int $l1, $l2 = false): string /** * read data value from parsed EDI data * - * @param array|string $filter 'AGR' - segment code - * or ['AGR',['1'=>'BB']], where AGR segment code and first element equal 'BB' - * or ['AGR',['1.0'=>'BB']], where AGR segment code and first element zero subelement - * equal 'BB' - * @param int $l1 first level item number (start by 1) - * @param int|false $l2 second level item number (start by 0) - * @param bool $required if required, but no exist, register error + * @param array|string $filter 'AGR' - segment code + * or ['AGR',['1'=>'BB']], where AGR segment code and first element equal 'BB' + * or ['AGR',['1.0'=>'BB']], where AGR segment code and first element zero subelement + * equal 'BB' + * @param int $l1 first level item number (start by 1) + * @param false|int $l2 second level item number (start by 0) + * @param bool $required if required, but no exist, register error * - * @return null|string + * @return string|null */ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = false) { @@ -221,6 +216,7 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = $filter_elements = false; } + // init $segment = false; $segment_count = 0; @@ -230,7 +226,7 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = if ($filter_elements) { $filter_ok = false; foreach ($filter_elements as $el_id => $el_value) { - $f_el_list = \explode('.', (string)$el_id); + $f_el_list = \explode('.', (string) $el_id); if (\count($f_el_list) === 1) { if ( isset($edi_row[$el_id]) @@ -238,9 +234,10 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = $edi_row[$el_id] == $el_value ) { $filter_ok = true; + break; } - } else if ( + } elseif ( isset($edi_row[$f_el_list[0]]) && ( @@ -262,6 +259,7 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = ) ) { $filter_ok = true; + break; } } @@ -271,7 +269,7 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = } } $segment = $edi_row; - $segment_count++; + ++$segment_count; } } @@ -286,7 +284,6 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = // found more one segment - error if ($segment_count > 1) { - $this->errors[] = 'Segment "' . $segment_name . '" is ambiguous'; return null; @@ -324,7 +321,7 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = * * @param int $PeriodQualifier period qualifier (codelist/2005) * - * @return string YYYY-MM-DD HH:MM:SS + * @return string|null YYYY-MM-DD HH:MM:SS */ public function readEdiSegmentDTM($PeriodQualifier) { @@ -348,6 +345,8 @@ public function readEdiSegmentDTM($PeriodQualifier) /** * @deprecated + * + * @return string|null */ public function readUNBDateTimeOfPpreperation() { @@ -356,6 +355,8 @@ public function readUNBDateTimeOfPpreperation() /** * @deprecated + * + * @return string|null */ public function readUNBDateTimeOfPreperation() { @@ -365,7 +366,7 @@ public function readUNBDateTimeOfPreperation() /** * get message preparation time * - * @return null|string + * @return string|null */ public function readUNBDateTimeOfPreparation() { @@ -373,14 +374,18 @@ public function readUNBDateTimeOfPreparation() $date = $this->readEdiDataValue('UNB', 4, 0); if (!empty($date)) { $time = $this->readEdiDataValue('UNB', 4, 1); - $datetime = \preg_replace('#(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '20$1-$2-$3 $4:$5:00', $date . $time); + if ($time !== null) { + $time = (string) \preg_replace('#(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '20$1-$2-$3 $4:$5:00', $date . $time); + } - return $datetime; + return $time; } // common YYYYMMDDHHMM $datetime = $this->readEdiDataValue('UNB', 4); - $datetime = \preg_replace('#(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '$1-$2-$3 $4:$5:00', $datetime); + if ($datetime !== null) { + $datetime = (string) \preg_replace('#(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '$1-$2-$3 $4:$5:00', $datetime); + } return $datetime; } @@ -390,9 +395,9 @@ public function readUNBDateTimeOfPreparation() * * @param mixed $transportStageQualifier * - * @return null|string + * @return string|null */ - public function readTDTtransportIdentification($transportStageQualifier): string + public function readTDTtransportIdentification($transportStageQualifier) { $transportIdentification = $this->readEdiDataValue(['TDT', ['1' => $transportStageQualifier]], 8, 0); if (!empty($transportIdentification)) { @@ -405,7 +410,7 @@ public function readTDTtransportIdentification($transportStageQualifier): string /** * read message type * - * @return null|string + * @return string|null */ public function readUNHmessageType() { @@ -415,7 +420,7 @@ public function readUNHmessageType() /** * read message number * - * @return null|string + * @return string|null */ public function readUNHmessageNumber() { @@ -430,7 +435,7 @@ public function readUNHmessageNumber() * @param string $end last segment of group * @param string $after segment after groups * - * @return false|array + * @return array|false */ public function readGroups(string $before, string $start, string $end, string $after) { @@ -443,6 +448,7 @@ public function readGroups(string $before, string $start, string $end, string $a // search before group segment if ($position == 'before_search' && $edi_row[0] == $before) { $position = 'before_is'; + continue; } @@ -458,18 +464,21 @@ public function readGroups(string $before, string $start, string $end, string $a if ($position == 'before_is' && $edi_row[0] == $start) { $position = 'group_is'; $group[] = $edi_row; + continue; } // if after before segment no start segment, search again before segment if ($position == 'before_is') { $position = 'before_search'; + continue; } // get group element if ($position == 'group_is' && $edi_row[0] != $end) { $group[] = $edi_row; + continue; } @@ -479,6 +488,7 @@ public function readGroups(string $before, string $start, string $end, string $a $group[] = $edi_row; $groups[] = $group; $group = []; + continue; } @@ -486,6 +496,7 @@ public function readGroups(string $before, string $start, string $end, string $a if ($position == 'group_finish' && $edi_row[0] == $start) { $group[] = $edi_row; $position = 'group_is'; + continue; } @@ -507,10 +518,10 @@ public function readGroups(string $before, string $start, string $end, string $a * Get groups from message when last segment is unknown but you know the barrier * useful for invoices by default. * - * @param string $start first segment start a new group - * @param array $barrier barrier segment (NOT in group) + * @param string $start first segment start a new group + * @param array $barrier barrier segment (NOT in group) * - * @return array + * @return array */ public function groupsExtract(string $start = 'LIN', array $barrier = ['UNS']): array { @@ -549,4 +560,27 @@ public function groupsExtract(string $start = 'LIN', array $barrier = ['UNS']): return $groups; } + + /** + * unwrap string splitting rows on terminator (if not escaped) + * + * @param string $string + * + * @return \Generator + */ + private static function unwrap($string) + { + $array = \preg_split("/(?analyser = new Analyser(); $this->mapping = new MappingProvider('D07A'); @@ -28,12 +31,12 @@ public function setUp() public function testGetMessageStructure() { $messageXml = $this->mapping->getMessage('tpfrep'); - $expected = include __DIR__ . "/../files/messages/tpfrep.php"; + $expected = include __DIR__ . '/../files/messages/tpfrep.php'; $actual = $this->analyser->loadMessageXml($messageXml); - $this->assertSame( + static::assertSame( $expected, $actual, - "Unable to get the correct message structure array" + 'Unable to get the correct message structure array' ); } @@ -41,9 +44,9 @@ public function testGetCodes() { $codesXml = $this->mapping->getCodes(); $actual = $this->analyser->loadCodesXml($codesXml); - $this->assertCount(270, $actual); - $this->assertArrayHasKey('1001', $actual); - $this->assertCount(652, $actual['1001']); + static::assertCount(270, $actual); + static::assertArrayHasKey('1001', $actual); + static::assertCount(652, $actual['1001']); } public function testGetSegmentStructure() @@ -51,30 +54,30 @@ public function testGetSegmentStructure() $segmentsXml = $this->mapping->getSegments(); /* @noinspection UnusedFunctionResultInspection */ $actual = $this->analyser->loadSegmentsXml($segmentsXml); - $this->assertCount(156, $actual); - $this->assertArrayHasKey('ADR', $actual); - $this->assertArrayHasKey('attributes', $actual['ADR']); - $this->assertArrayHasKey('details', $actual['ADR']); - $this->assertCount(3, $actual['ADR']['attributes']); + static::assertCount(156, $actual); + static::assertArrayHasKey('ADR', $actual); + static::assertArrayHasKey('attributes', $actual['ADR']); + static::assertArrayHasKey('details', $actual['ADR']); + static::assertCount(3, $actual['ADR']['attributes']); } public function testProcess() { - $parser = new Parser(__DIR__ . "/../files/example.edi"); + $parser = new Parser(__DIR__ . '/../files/example.edi'); $parsed = $parser->get(); $segments = $parser->getRawSegments(); - $this->assertSame(15, \count($parsed)); + static::assertCount(15, $parsed); $result = (new Analyser())->process($parsed, $segments); - $this->assertSame(399, \strlen($result)); + static::assertSame(399, \strlen($result)); } public function testProcessWrapped() { - $parser = new Parser(__DIR__ . "/../files/example_wrapped.edi"); + $parser = new Parser(__DIR__ . '/../files/example_wrapped.edi'); $parsed = $parser->get(); $segments = $parser->getRawSegments(); - $this->assertSame(15, \count($parsed)); + static::assertCount(15, $parsed); $result = (new Analyser())->process($parsed, $segments); - $this->assertSame(399, \strlen($result)); + static::assertSame(399, \strlen($result)); } } diff --git a/tests/EDITest/EncoderTest.php b/tests/EDITest/EncoderTest.php index f0e27e8f..85886a17 100644 --- a/tests/EDITest/EncoderTest.php +++ b/tests/EDITest/EncoderTest.php @@ -4,44 +4,47 @@ use EDI\Encoder; -class EncoderTest extends \PHPUnit\Framework\TestCase +/** + * @internal + */ +final class EncoderTest extends \PHPUnit\Framework\TestCase { public function testEncodeNull() { $message = null; $e = new Encoder($message); - $this->assertInstanceOf('EDI\Encoder', $e); + static::assertInstanceOf('EDI\Encoder', $e); } public function testEncodeMessage() { - $message = [["LOC", "9", "VNSGN"], ["LOC", "11", "ITGOA"], ["MEA", "WT", "", ["KGM", "9040"]]]; + $message = [['LOC', '9', 'VNSGN'], ['LOC', '11', 'ITGOA'], ['MEA', 'WT', '', ['KGM', '9040']]]; $expected = "LOC+9+VNSGN'LOC+11+ITGOA'MEA+WT++KGM:9040'"; $res = (new Encoder($message))->get(); - $this->assertSame($expected, $res); + static::assertSame($expected, $res); } public function testEncodeMessageNotWrapped() { - $message = [["LOC", "9", "VNSGN"], ["LOC", "11", "ITGOA"], ["MEA", "WT", "", ["KGM", "9040"]]]; + $message = [['LOC', '9', 'VNSGN'], ['LOC', '11', 'ITGOA'], ['MEA', 'WT', '', ['KGM', '9040']]]; $expected = "LOC+9+VNSGN'\nLOC+11+ITGOA'\nMEA+WT++KGM:9040'"; $res = (new Encoder($message, false))->get(); - $this->assertSame($expected, $res); + static::assertSame($expected, $res); } public function testEncodeMessageWithUNA() { - $message = [["LOC", "9", "VNSGN"], ["LOC", "11", "ITGOA"], ["MEA", "WT", "", ["KGM", "9040"]]]; + $message = [['LOC', '9', 'VNSGN'], ['LOC', '11', 'ITGOA'], ['MEA', 'WT', '', ['KGM', '9040']]]; $expected = "UNA:+.? 'LOC+9+VNSGN'LOC+11+ITGOA'MEA+WT++KGM:9040'"; $e = new Encoder($message); - $e->setUNA("&+.?"); + $e->setUNA('&+.?'); $e->disableUNA(); $e->enableUNA(); $res = $e->get(); - $this->assertSame($expected, $res); + static::assertSame($expected, $res); $e->setUNA("&+.? '", true); $res2 = $e->get(); $expected2 = "UNA&+.? 'LOC+9+VNSGN'LOC+11+ITGOA'MEA+WT++KGM&9040'"; - $this->assertSame($expected2, $res2); + static::assertSame($expected2, $res2); } } diff --git a/tests/EDITest/InterpreterTest.php b/tests/EDITest/InterpreterTest.php index 030849f0..768869e8 100644 --- a/tests/EDITest/InterpreterTest.php +++ b/tests/EDITest/InterpreterTest.php @@ -6,12 +6,14 @@ use EDI\Interpreter; use EDI\Parser; -class InterpreterTest extends \PHPUnit\Framework\TestCase +/** + * @internal + */ +final class InterpreterTest extends \PHPUnit\Framework\TestCase { - public function testCOARRI() { - $parser = new Parser(__DIR__ . "/../files/D95BCOARRI.edi"); + $parser = new Parser(__DIR__ . '/../files/D95BCOARRI.edi'); $mapping = new \EDI\Mapping\MappingProvider('D95B'); $analyser = new Analyser(); @@ -22,14 +24,14 @@ public function testCOARRI() /** @noinspection UnusedFunctionResultInspection */ $interpreter->prepare($parser->get()); - $this->assertCount(3, $interpreter->getMessages()); //2 + service - $this->assertCount(0, $interpreter->getErrors()); - $this->assertCount(2, $interpreter->getServiceSegments()); + static::assertCount(3, $interpreter->getMessages()); //2 + service + static::assertCount(0, $interpreter->getErrors()); + static::assertCount(2, $interpreter->getServiceSegments()); } public function testServiceSegments() { - $parser = new Parser(__DIR__ . "/../files/D95BCOARRI.edi"); + $parser = new Parser(__DIR__ . '/../files/D95BCOARRI.edi'); $mapping = new \EDI\Mapping\MappingProvider('D95B'); $analyser = new Analyser(); @@ -42,13 +44,13 @@ public function testServiceSegments() $svc = $interpreter->getServiceSegments(); $svcjson = $interpreter->getJsonServiceSegments(); $svcjsonpretty = $interpreter->getJsonServiceSegments(true); - $this->assertSame($svc, json_decode($svcjson, true)); - $this->assertSame(26, substr_count($svcjsonpretty, "\n")); + static::assertSame($svc, \json_decode($svcjson, true)); + static::assertSame(26, \substr_count($svcjsonpretty, "\n")); } public function testBAPLIE() { - $parser = new Parser(__DIR__ . "/../files/D95BBAPLIE.edi"); + $parser = new Parser(__DIR__ . '/../files/D95BBAPLIE.edi'); $mapping = new \EDI\Mapping\MappingProvider('D95B'); $analyser = new Analyser(); @@ -59,16 +61,16 @@ public function testBAPLIE() /** @noinspection UnusedFunctionResultInspection */ $interpreter->prepare($parser->get()); - $this->assertCount(2, $interpreter->getMessages()); - $this->assertCount(0, $interpreter->getErrors()); - $this->assertCount(2, $interpreter->getServiceSegments()); + static::assertCount(2, $interpreter->getMessages()); + static::assertCount(0, $interpreter->getErrors()); + static::assertCount(2, $interpreter->getServiceSegments()); - $this->assertSame([], $interpreter->getErrors()); + static::assertSame([], $interpreter->getErrors()); } public function testDESADV() { - $parser = new Parser(__DIR__ . "/../files/D96ADESADV.edi"); + $parser = new Parser(__DIR__ . '/../files/D96ADESADV.edi'); $mapping = new \EDI\Mapping\MappingProvider('D96A'); $analyser = new Analyser(); @@ -79,19 +81,19 @@ public function testDESADV() /** @noinspection UnusedFunctionResultInspection */ $interpreter->prepare($parser->get()); - $this->assertJsonStringEqualsJsonFile( - __DIR__ . "/../files/D96ADESADV.json", + static::assertJsonStringEqualsJsonFile( + __DIR__ . '/../files/D96ADESADV.json', $interpreter->getJson(true), - "JSON does not match expected output" + 'JSON does not match expected output' ); - $this->assertSame(3152, \strlen($interpreter->getJson())); - $this->assertSame(8379, \strlen($interpreter->getJson(true))); + static::assertSame(3152, \strlen($interpreter->getJson())); + static::assertSame(8379, \strlen($interpreter->getJson(true))); - $this->assertCount(2, $interpreter->getMessages()); - $this->assertCount(0, $interpreter->getErrors()); - $this->assertCount(2, $interpreter->getServiceSegments()); - $this->assertSame([], $interpreter->getErrors()); + static::assertCount(2, $interpreter->getMessages()); + static::assertCount(0, $interpreter->getErrors()); + static::assertCount(2, $interpreter->getServiceSegments()); + static::assertSame([], $interpreter->getErrors()); } public function testMissingUNTUNZ() @@ -107,17 +109,17 @@ public function testMissingUNTUNZ() /** @noinspection UnusedFunctionResultInspection */ $interpreter->prepare($parser->get()); $errors = $interpreter->getErrors(); - $this->assertCount(2, $errors); + static::assertCount(2, $errors); $segments = []; foreach ($errors as $err) { $segments[] = $err['segmentId']; } - $this->assertSame(['UNZ', 'UNT'], $segments); + static::assertSame(['UNZ', 'UNT'], $segments); } public function testOrderError() { - $edi = file_get_contents(__DIR__ . '/../files/example_order_error.edi'); + $edi = \file_get_contents(__DIR__ . '/../files/example_order_error.edi'); $parser = new Parser($edi); $mapping = new \EDI\Mapping\MappingProvider('D95B'); $analyser = new Analyser(); @@ -127,7 +129,7 @@ public function testOrderError() $interpreter = new Interpreter($mapping->getMessage('ORDERS'), $segs, $svc); /** @noinspection UnusedFunctionResultInspection */ $interpreter->prepare($parser->get()); - $this->assertSame( + static::assertSame( [ 0 => 'There\'s a character not escaped with ? in the data; string :::H-Vollmilch 3,5% ?*?*Marke?*?*:1l Tertra mit Drehverschluss', ], @@ -135,26 +137,26 @@ public function testOrderError() ); $errors = $interpreter->getErrors(); - $this->assertCount(3, $errors); + static::assertCount(3, $errors); $segments = []; foreach ($errors as $err) { $segments[] = $err['segmentId']; } - $this->assertSame(['IMD', 'IMD', 'IMD'], $segments); + static::assertSame(['IMD', 'IMD', 'IMD'], $segments); - $this->assertCount(2, $interpreter->getMessages()); + static::assertCount(2, $interpreter->getMessages()); - $this->assertContains('"messageHeader"', $interpreter->getJson(true)); - $this->assertContains('"interchangeHeader"', $interpreter->getJsonServiceSegments(true)); + static::assertContains('"messageHeader"', $interpreter->getJson(true)); + static::assertContains('"interchangeHeader"', $interpreter->getJsonServiceSegments(true)); $arrayy = $interpreter->getArrayy(); - $this->assertSame( + static::assertSame( 'Butter 40x250g Alu', $arrayy->get('0.SG25.0.itemDescription.itemDescription.itemDescription') ); $arrayy = $interpreter->getArrayyServiceSegments(); - $this->assertCount( + static::assertCount( 13, $arrayy->get('interchangeHeader') ); @@ -162,7 +164,7 @@ public function testOrderError() public function testOrderOk() { - $edi = file_get_contents(__DIR__ . '/../files/example_order_ok.edi'); + $edi = \file_get_contents(__DIR__ . '/../files/example_order_ok.edi'); $parser = new Parser($edi); $mapping = new \EDI\Mapping\MappingProvider('D95B'); $analyser = new Analyser(); @@ -172,24 +174,24 @@ public function testOrderOk() $interpreter = new Interpreter($mapping->getMessage('ORDERS'), $segs, $svc); /** @noinspection UnusedFunctionResultInspection */ $interpreter->prepare($parser->get()); - $this->assertSame([], $parser->errors()); + static::assertSame([], $parser->errors()); $errors = $interpreter->getErrors(); - $this->assertCount(0, $errors); + static::assertCount(0, $errors); - $this->assertCount(2, $interpreter->getMessages()); + static::assertCount(2, $interpreter->getMessages()); - $this->assertContains('"messageHeader"', $interpreter->getJson(true)); - $this->assertContains('"interchangeHeader"', $interpreter->getJsonServiceSegments(true)); + static::assertContains('"messageHeader"', $interpreter->getJson(true)); + static::assertContains('"interchangeHeader"', $interpreter->getJsonServiceSegments(true)); $arrayy = $interpreter->getArrayy(); - $this->assertSame( + static::assertSame( 'Butter 40x250g Alu', $arrayy->get('0.SG25.0.itemDescription.itemDescription.itemDescription') ); $arrayy = $interpreter->getArrayyServiceSegments(); - $this->assertCount( + static::assertCount( 13, $arrayy->get('interchangeHeader') ); @@ -212,8 +214,8 @@ public function testMissingUNBUNH() foreach ($errors as $err) { $segments[] = $err['segmentId']; } - $this->assertContains('UNB', $segments); - $this->assertContains('UNH', $segments); + static::assertContains('UNB', $segments); + static::assertContains('UNH', $segments); } public function testTooManyElements() @@ -229,7 +231,7 @@ public function testTooManyElements() $p = $interpreter->prepare($parser->get()); $errors = $interpreter->getErrors(); $svcSegs = $interpreter->getServiceSegments(); - $this->assertCount(0, $errors); - $this->assertArrayHasKey('Extension2', $svcSegs['interchangeTrailer']); + static::assertCount(0, $errors); + static::assertArrayHasKey('Extension2', $svcSegs['interchangeTrailer']); } } diff --git a/tests/EDITest/ParserTest.php b/tests/EDITest/ParserTest.php index b791c168..307bf739 100644 --- a/tests/EDITest/ParserTest.php +++ b/tests/EDITest/ParserTest.php @@ -6,7 +6,10 @@ use EDI\Parser; -class ParserTest extends \PHPUnit\Framework\TestCase +/** + * @internal + */ +final class ParserTest extends \PHPUnit\Framework\TestCase { public function testCustomStripRegex() { @@ -15,8 +18,8 @@ public function testCustomStripRegex() $string = "LOC+11+ITGOA'MEA+WT++KGM:9040'"; $test = $p->loadString($string); - $expected = [["LOC", "11", "ITGOA"], ["MEA", "WT", "", ["KGM", "9040"]]]; - $this->assertSame($expected, $test); + $expected = [['LOC', '11', 'ITGOA'], ['MEA', 'WT', '', ['KGM', '9040']]]; + static::assertSame($expected, $test); } public function testMessageUnwrap() @@ -25,16 +28,16 @@ public function testMessageUnwrap() $string = "LOC+11+ITGOA'MEA+WT++KGM:9040'"; $test = $p->loadString($string); - $expected = [["LOC", "11", "ITGOA"], ["MEA", "WT", "", ["KGM", "9040"]]]; - $this->assertSame($expected, $test); + $expected = [['LOC', '11', 'ITGOA'], ['MEA', 'WT', '', ['KGM', '9040']]]; + static::assertSame($expected, $test); } public function testArrayUnwrap() { $arr = ["LOC+11+ITGOA'MEA+WT++KGM:9040'"]; $test = (new Parser($arr))->get(); - $expected = [["LOC", "11", "ITGOA"], ["MEA", "WT", "", ["KGM", "9040"]]]; - $this->assertSame($expected, $test); + $expected = [['LOC', '11', 'ITGOA'], ['MEA', 'WT', '', ['KGM', '9040']]]; + static::assertSame($expected, $test); } public function testGetRawSegments() @@ -42,105 +45,104 @@ public function testGetRawSegments() $txt = "LOC+11+ITGOA'MEA+WT++KGM:9040'"; $test = (new Parser($txt))->getRawSegments(); $expected = ["LOC+11+ITGOA'", "MEA+WT++KGM:9040'"]; - $this->assertSame($expected, $test); + static::assertSame($expected, $test); } public function testParseSimple() { $p = new Parser(); $array = ["LOC+9+VNSGN'", "LOC+11+ITGOA'", "MEA+WT++KGM:9040'"]; - $expected = [["LOC", "9", "VNSGN"], ["LOC", "11", "ITGOA"], ["MEA", "WT", "", ["KGM", "9040"]]]; + $expected = [['LOC', '9', 'VNSGN'], ['LOC', '11', 'ITGOA'], ['MEA', 'WT', '', ['KGM', '9040']]]; $result = $p->parse($array); - $this->assertSame($expected, $result); + static::assertSame($expected, $result); } public function testEscapedSegment() { - $string = "EQD+CX??DU12?+3456+2?:0'"; - $expected = [["EQD", "CX?DU12+3456", "2:0"]]; + $expected = [['EQD', 'CX?DU12+3456', '2:0']]; $result = (new Parser($string))->get(); - $this->assertSame($expected, $result); + static::assertSame($expected, $result); } /** @dataProvider multipleEscapedSegmentsProvider */ - public function testMultipleEscapedSegments($string,$expected) + public function testMultipleEscapedSegments($string, $expected) { $result = (new Parser($string))->get(); - $this->assertSame($expected,$result); + static::assertSame($expected, $result); } public function multipleEscapedSegmentsProvider() { return [ - ["EQD+CX??DU12?+3456+2?:0'", [["EQD", "CX?DU12+3456", "2:0"]]], - ["EQD+CX????DU12?+3456+2?:0'", [["EQD", "CX??DU12+3456", "2:0"]]], - ["EQD+CX??????DU12?+3456+2?:0'", [["EQD", "CX???DU12+3456", "2:0"]]], - ["EQD+CX????????DU12?+3456+2?:0'",[["EQD", "CX????DU12+3456", "2:0"]]], - ["EQD+CX??DU12?+3456+2?:0??'", [["EQD", "CX?DU12+3456", "2:0?"]]], - ["EQD+CX??DU12?+3456+2?:0????'", [["EQD", "CX?DU12+3456", "2:0??"]]], - ["EQD+CX??DU12?+3456+2?:0??????'",[["EQD", "CX?DU12+3456", "2:0???"]]], - ["??EQD+CX??DU12?+3456+2?:0'", [["?EQD", "CX?DU12+3456", "2:0"]]], - ["????EQD+CX??DU12?+3456+2?:0'", [["??EQD", "CX?DU12+3456", "2:0"]]], - ["??????EQD+CX??DU12?+3456+2?:0'",[["???EQD", "CX?DU12+3456", "2:0"]]], - ["EQD??+CX??DU12?+3456+2?:0'", [["EQD?", "CX?DU12+3456", "2:0"]]], - ["EQD????+CX??DU12?+3456+2?:0'", [["EQD??", "CX?DU12+3456", "2:0"]]], - ["EQD??????+CX??DU12?+3456+2?:0'",[["EQD???", "CX?DU12+3456", "2:0"]]], - ["EQD+??CX??DU12?+3456+2?:0'", [["EQD", "?CX?DU12+3456", "2:0"]]], - ["EQD+????CX??DU12?+3456+2?:0'", [["EQD", "??CX?DU12+3456", "2:0"]]], - ["EQD+??????CX??DU12?+3456+2?:0'",[["EQD", "???CX?DU12+3456", "2:0"]]], + ["EQD+CX??DU12?+3456+2?:0'", [['EQD', 'CX?DU12+3456', '2:0']]], + ["EQD+CX????DU12?+3456+2?:0'", [['EQD', 'CX??DU12+3456', '2:0']]], + ["EQD+CX??????DU12?+3456+2?:0'", [['EQD', 'CX???DU12+3456', '2:0']]], + ["EQD+CX????????DU12?+3456+2?:0'", [['EQD', 'CX????DU12+3456', '2:0']]], + ["EQD+CX??DU12?+3456+2?:0??'", [['EQD', 'CX?DU12+3456', '2:0?']]], + ["EQD+CX??DU12?+3456+2?:0????'", [['EQD', 'CX?DU12+3456', "2:0??'"]]], // TODO? -> ' is correct here? + ["EQD+CX??DU12?+3456+2?:0??????'", [['EQD', 'CX?DU12+3456', "2:0???'"]]], // TODO? -> ' is correct here? + ["??EQD+CX??DU12?+3456+2?:0'", [['?EQD', 'CX?DU12+3456', '2:0']]], + ["????EQD+CX??DU12?+3456+2?:0'", [['??EQD', 'CX?DU12+3456', '2:0']]], + ["??????EQD+CX??DU12?+3456+2?:0'", [['???EQD', 'CX?DU12+3456', '2:0']]], + ["EQD??+CX??DU12?+3456+2?:0'", [['EQD?', 'CX?DU12+3456', '2:0']]], + ["EQD????+CX??DU12?+3456+2?:0'", [['EQD??', 'CX?DU12+3456', '2:0']]], + ["EQD??????+CX??DU12?+3456+2?:0'", [['EQD???', 'CX?DU12+3456', '2:0']]], + ["EQD+??CX??DU12?+3456+2?:0'", [['EQD', '?CX?DU12+3456', '2:0']]], + ["EQD+????CX??DU12?+3456+2?:0'", [['EQD', '??CX?DU12+3456', '2:0']]], + ["EQD+??????CX??DU12?+3456+2?:0'", [['EQD', '???CX?DU12+3456', '2:0']]], ]; } public function testFileOk() { - $string = file_get_contents(__DIR__ . '/../files/example_order_ok.edi'); + $string = \file_get_contents(__DIR__ . '/../files/example_order_ok.edi'); - for ($i = 0; $i < 100; $i++) { // keep for simple performance tests + for ($i = 0; $i < 100; ++$i) { // keep for simple performance tests $errors = (new Parser($string))->errors(); } - $this->assertSame([], $errors); + static::assertSame([], $errors); - $data = json_encode((new Parser($string))->get()); - $this->assertContains('Sup 1:10', $data); - $this->assertNotContains('Konzentrat:o', $data); - $this->assertContains('"Rindfleischsuppe Konzentrat","o', $data); + $data = \json_encode((new Parser($string))->get()); + static::assertContains('Sup 1:10', $data); + static::assertNotContains('Konzentrat:o', $data); + static::assertContains('"Rindfleischsuppe Konzentrat","o', $data); } public function testFileError() { - $string = file_get_contents(__DIR__ . '/../files/example_order_error.edi'); + $string = \file_get_contents(__DIR__ . '/../files/example_order_error.edi'); $errors = (new Parser($string))->errors(); - $this->assertSame( + static::assertSame( [ 0 => 'There\'s a character not escaped with ? in the data; string :::H-Vollmilch 3,5% ?*?*Marke?*?*:1l Tertra mit Drehverschluss', - ] - , $errors + ], + $errors ); } public function testNotPrintableCharacter() { $string = "EQD+CèèèXDU12?+3456+2?:0'"; - $expected = [["EQD", "CXDU12+3456", "2:0"]]; + $expected = [['EQD', 'CXDU12+3456', '2:0']]; $p = new Parser($string); $result = $p->get(); $experror = "There's a not printable character on line 1: EQD+CèèèXDU12?+3456+2?:0'"; $error = $p->errors(); - $this->assertSame($expected, $result); - $this->assertContains($experror, $error); + static::assertSame($expected, $result); + static::assertContains($experror, $error); } public function testNotEscapedSegment() { $string = "EQD+CX?DU12?+3456+2?:0'"; - $expected = [["EQD", "CX?DU12+3456", "2:0"]]; + $expected = [['EQD', 'CX?DU12+3456', '2:0']]; $p = new Parser($string); $result = $p->get(); $experror = "There's a character not escaped with ? in the data; string CX?DU12?+3456"; $error = $p->errors(); - $this->assertSame($expected, $result); - $this->assertContains($experror, $error); + static::assertSame($expected, $result); + static::assertContains($experror, $error); } public function testSegmentWithMultipleSingleQuotes() @@ -150,63 +152,63 @@ public function testSegmentWithMultipleSingleQuotes() $result = $p->parse($string); $experror = "There's a ' not escaped in the data; string EQD+CX'DU12?+3456+2?:0"; $error = $p->errors(); - $this->assertContains($experror, $error); + static::assertContains($experror, $error); } public function testArrayInputNoErrors() { $arr = ["LOC+9+VNSGN'", "LOC+11+ITGOA'"]; $result = (new Parser($arr))->errors(); - $this->assertEmpty($result); + static::assertEmpty($result); } public function testArrayInputEmptyLine() { - $arr = ["LOC+9+VNSGN'", "", "LOC+11+ITGOA'"]; + $arr = ["LOC+9+VNSGN'", '', "LOC+11+ITGOA'"]; $result = (new Parser($arr))->errors(); - $this->assertEmpty($result); + static::assertEmpty($result); } public function testLoadFile() { - $result = (new Parser(__DIR__ . "/../files/example.edi"))->errors(); - $this->assertEmpty($result); + $result = (new Parser(__DIR__ . '/../files/example.edi'))->errors(); + static::assertEmpty($result); } public function testLoadWrappedFile() { - $result = (new Parser(__DIR__ . "/../files/example_wrapped.edi"))->errors(); - $this->assertEmpty($result); + $result = (new Parser(__DIR__ . '/../files/example_wrapped.edi'))->errors(); + static::assertEmpty($result); } public function testUNHWithoutMessageType() { - $arr = ["UNH+123", "LOC+9+VNSGN'", "LOC+11+ITGOA'"]; + $arr = ['UNH+123', "LOC+9+VNSGN'", "LOC+11+ITGOA'"]; $p = new Parser($arr); - $this->assertNull($p->getMessageFormat()); - $this->assertNull($p->getMessageDirectory()); + static::assertNull($p->getMessageFormat()); + static::assertNull($p->getMessageDirectory()); } public function testUNHData() { $arr = ["UNH+1452515553811+COARRI:D:95B:UN:ITG13'"]; $p = new Parser($arr); - $this->assertSame("COARRI", $p->getMessageFormat()); - $this->assertSame("95B", $p->getMessageDirectory()); + static::assertSame('COARRI', $p->getMessageFormat()); + static::assertSame('95B', $p->getMessageDirectory()); } public function testUNHDataOnlyFormat() { $arr = ["UNH+1452515553811+COARRI'"]; $p = new Parser($arr); - $this->assertSame("COARRI", $p->getMessageFormat()); - $this->assertNull($p->getMessageDirectory()); + static::assertSame('COARRI', $p->getMessageFormat()); + static::assertNull($p->getMessageDirectory()); } public function testUNAString() { - $result = (new Parser(["UNA:+.? '", "UNH+123", "LOC+9+VNSGN'"]))->errors(); - $this->assertEmpty($result); + $result = (new Parser(["UNA:+.? '", 'UNH+123', "LOC+9+VNSGN'"]))->errors(); + static::assertEmpty($result); } /* @@ -217,36 +219,35 @@ public function testBigFile() $result = $p->errors(); $this->assertSame([], $result); } - */ + */ public function testReleaseCharacter() { $p = new Parser(); - $loaded = $p->load(__DIR__ . "/../files/example_release_character.edi"); + $loaded = $p->load(__DIR__ . '/../files/example_release_character.edi'); $result = $p->errors(); - $this->assertEmpty($result); + static::assertEmpty($result); - $this->assertSame($loaded[5][2], 'NO MORE FLIGHTS 1'); - $this->assertSame($loaded[6][2], 'NO MORE FLIGHTS 2?'); - $this->assertSame($loaded[7][2], 'NO MORE \' FLIGHTS 3'); - $this->assertSame($loaded[8][2], 'NO MORE ? FLIGHTS 3'); - $this->assertSame($loaded[9][2], 'NO MORE ?\' FLIGHTS 3'); + static::assertSame($loaded[5][2], 'NO MORE FLIGHTS 1'); + static::assertSame($loaded[6][2], 'NO MORE FLIGHTS 2?'); + static::assertSame($loaded[7][2], 'NO MORE \' FLIGHTS 3'); + static::assertSame($loaded[8][2], 'NO MORE ? FLIGHTS 3'); + static::assertSame($loaded[9][2], 'NO MORE ?\' FLIGHTS 3'); - $this->assertSame($loaded[10][2], 'FIELD 1'); - $this->assertSame($loaded[10][3], 'FIELD 2'); + static::assertSame($loaded[10][2], 'FIELD 1'); + static::assertSame($loaded[10][3], 'FIELD 2'); - $this->assertSame($loaded[11][2], 'FIELD 1?'); - $this->assertSame($loaded[11][3], 'FIELD 2'); + static::assertSame($loaded[11][2], 'FIELD 1?'); + static::assertSame($loaded[11][3], 'FIELD 2'); - $this->assertSame($loaded[12][2], 'FIELD 1?+FIELD 2'); + static::assertSame($loaded[12][2], 'FIELD 1?+FIELD 2'); - $this->assertSame($loaded[13][2][0], 'FIELD 1.1'); - $this->assertSame($loaded[13][2][1], 'FIELD 1.2'); + static::assertSame($loaded[13][2][0], 'FIELD 1.1'); + static::assertSame($loaded[13][2][1], 'FIELD 1.2'); - $this->assertSame($loaded[14][2][0], 'FIELD 1.1?'); - $this->assertSame($loaded[14][2][1], 'FIELD 1.2'); + static::assertSame($loaded[14][2][0], 'FIELD 1.1?'); + static::assertSame($loaded[14][2][1], 'FIELD 1.2'); - $this->assertSame($loaded[15][2], 'FIELD 1.1?:FIELD 1.2'); + static::assertSame($loaded[15][2], 'FIELD 1.1?:FIELD 1.2'); } - } diff --git a/tests/EDITest/ReaderTest.php b/tests/EDITest/ReaderTest.php index 82c3a7c9..385451b0 100644 --- a/tests/EDITest/ReaderTest.php +++ b/tests/EDITest/ReaderTest.php @@ -6,74 +6,75 @@ use EDI\Reader; -class ReaderTest extends \PHPUnit\Framework\TestCase +/** + * @internal + */ +final class ReaderTest extends \PHPUnit\Framework\TestCase { public function testReadEdiDataValue() { - $r = new Reader(__DIR__ . "/../files/example.edi"); + $r = new Reader(__DIR__ . '/../files/example.edi'); $sender = $r->readEdiDataValue('UNB', 2); - $this->assertSame('6XPPC', $sender); + static::assertSame('6XPPC', $sender); $unh2 = $r->readEdiDataValue(['UNH', ['1' => '1']], 2); - $this->assertSame('PAORES', $unh2[0]); + static::assertSame('PAORES', $unh2[0]); $unh1 = $r->readEdiDataValue(['UNH', ['2.0' => 'PAORES']], 1); - $this->assertSame('1', $unh1); + static::assertSame('1', $unh1); } public function testReadUNBDateTimeOfPpreperation() { - $Dt = (new Reader(__DIR__ . "/../files/example.edi"))->readUNBDateTimeOfPpreperation(); - $this->assertSame('2094-01-01 09:50:00', $Dt); + $Dt = (new Reader(__DIR__ . '/../files/example.edi'))->readUNBDateTimeOfPpreperation(); + static::assertSame('2094-01-01 09:50:00', $Dt); } public function testReadUNBDateTimeOfPreperation() { - $Dt = (new Reader(__DIR__ . "/../files/example.edi"))->readUNBDateTimeOfPreperation(); - $this->assertSame('2094-01-01 09:50:00', $Dt); + $Dt = (new Reader(__DIR__ . '/../files/example.edi'))->readUNBDateTimeOfPreperation(); + static::assertSame('2094-01-01 09:50:00', $Dt); } public function testReadUNBDateTimeOfPreparation() { - $Dt = (new Reader(__DIR__ . "/../files/example.edi"))->readUNBDateTimeOfPreparation(); - $this->assertSame('2094-01-01 09:50:00', $Dt); + $Dt = (new Reader(__DIR__ . '/../files/example.edi'))->readUNBDateTimeOfPreparation(); + static::assertSame('2094-01-01 09:50:00', $Dt); } public function testReadUNHmessageType() { - $messageType = (new Reader(__DIR__ . "/../files/example.edi"))->readUNHmessageType(); - $this->assertSame('PAORES', $messageType); + $messageType = (new Reader(__DIR__ . '/../files/example.edi'))->readUNHmessageType(); + static::assertSame('PAORES', $messageType); } public function testReadUNHmessageNumber() { - $messageNumber = (new Reader(__DIR__ . "/../files/example.edi"))->readUNHmessageNumber(); - $this->assertSame('1', $messageNumber); + $messageNumber = (new Reader(__DIR__ . '/../files/example.edi'))->readUNHmessageNumber(); + static::assertSame('1', $messageNumber); } - public function testpreValidate() { - $errors = (new Reader(__DIR__ . "/../files/exampleMulti.edi"))->errors(); - $this->assertArrayHasKey(0, $errors); + $errors = (new Reader(__DIR__ . '/../files/exampleMulti.edi'))->errors(); + static::assertArrayHasKey(0, $errors); - $this->assertSame('File has multiple messages', $errors[0]); + static::assertSame('File has multiple messages', $errors[0]); } public function testSplitMultiMessage() { - $multiEdi = file_get_contents(__DIR__ . "/../files/exampleMulti.edi"); + $multiEdi = \file_get_contents(__DIR__ . '/../files/exampleMulti.edi'); $eddies = Reader::splitMultiMessage($multiEdi); - $this->assertSame(2, \count($eddies)); + static::assertCount(2, $eddies); $r = new Reader($eddies[0]); $messageType = $r->readUNHmessageType(); - $this->assertSame('PAORES', $messageType); + static::assertSame('PAORES', $messageType); $r = new Reader($eddies[1]); $messageType = $r->readUNHmessageType(); - $this->assertSame('PAORES', $messageType); + static::assertSame('PAORES', $messageType); } - } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a1417632..900c8b92 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,12 +1,12 @@ - array ( - '0065' => 'TPFREP', - '0052' => 'D', - '0054' => '07A', - '0051' => 'UN', - ), - 'segments' => - array ( - 0 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'UNH', - 'maxrepeat' => '1', - 'required' => 'true', - ), - ), - 1 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'BGM', - 'maxrepeat' => '1', - 'required' => 'true', - ), - ), - 2 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'DTM', - 'maxrepeat' => '1', - ), - ), - 3 => - array ( - 'type' => 'group', - 'attributes' => - array ( - 'id' => 'SG1', - 'maxrepeat' => '1', - 'required' => 'true', - ), - 'details' => - array ( - 0 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'TDT', - 'maxrepeat' => '1', - 'required' => 'true', - ), - ), - 1 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'LOC', - 'maxrepeat' => '1', - 'required' => 'true', - ), - ), - 2 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'DTM', - 'maxrepeat' => '9', - ), - ), - 3 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'RFF', - 'maxrepeat' => '9', - ), - ), - ), - ), - 4 => - array ( - 'type' => 'group', - 'attributes' => - array ( - 'id' => 'SG2', - 'maxrepeat' => '99', - ), - 'details' => - array ( - 0 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'EQD', - 'maxrepeat' => '1', - 'required' => 'true', - ), - ), - 1 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'CNT', - 'maxrepeat' => '99', - ), - ), - 2 => - array ( - 'type' => 'group', - 'attributes' => - array ( - 'id' => 'SG3', - 'maxrepeat' => '999', - ), - 'details' => - array ( - 0 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'DTM', +[ + 'defaults' => [ + '0065' => 'TPFREP', + '0052' => 'D', + '0054' => '07A', + '0051' => 'UN', + ], + 'segments' => [ + 0 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'UNH', 'maxrepeat' => '1', - 'required' => 'true', - ), - ), - 1 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'FTX', - 'maxrepeat' => '9', - ), - ), - ), - ), - ), - ), - 5 => - array ( - 'type' => 'segment', - 'attributes' => - array ( - 'id' => 'UNT', - 'maxrepeat' => '1', - 'required' => 'true', - ), - ), - ), -); + 'required' => 'true', + ], + ], + 1 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'BGM', + 'maxrepeat' => '1', + 'required' => 'true', + ], + ], + 2 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'DTM', + 'maxrepeat' => '1', + ], + ], + 3 => [ + 'type' => 'group', + 'attributes' => [ + 'id' => 'SG1', + 'maxrepeat' => '1', + 'required' => 'true', + ], + 'details' => [ + 0 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'TDT', + 'maxrepeat' => '1', + 'required' => 'true', + ], + ], + 1 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'LOC', + 'maxrepeat' => '1', + 'required' => 'true', + ], + ], + 2 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'DTM', + 'maxrepeat' => '9', + ], + ], + 3 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'RFF', + 'maxrepeat' => '9', + ], + ], + ], + ], + 4 => [ + 'type' => 'group', + 'attributes' => [ + 'id' => 'SG2', + 'maxrepeat' => '99', + ], + 'details' => [ + 0 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'EQD', + 'maxrepeat' => '1', + 'required' => 'true', + ], + ], + 1 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'CNT', + 'maxrepeat' => '99', + ], + ], + 2 => [ + 'type' => 'group', + 'attributes' => [ + 'id' => 'SG3', + 'maxrepeat' => '999', + ], + 'details' => [ + 0 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'DTM', + 'maxrepeat' => '1', + 'required' => 'true', + ], + ], + 1 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'FTX', + 'maxrepeat' => '9', + ], + ], + ], + ], + ], + ], + 5 => [ + 'type' => 'segment', + 'attributes' => [ + 'id' => 'UNT', + 'maxrepeat' => '1', + 'required' => 'true', + ], + ], + ], +];