From b129d62ba9625daeccdc83ed6b16ee7ff34ea685 Mon Sep 17 00:00:00 2001 From: Nadyita Date: Sat, 13 Apr 2024 09:36:57 +0200 Subject: [PATCH] Lots of renaming and cleanup --- .php-cs-fixer.cache | 2 +- .php-cs-fixer.dist.php | 12 + .php-cs-fixer.php | 258 ------------------ .vscode/settings.json | 2 +- composer.json | 5 + composer.lock | 228 +++++++++------- src/BinaryPackage.php | 8 +- src/Client/MultiClient.php | 40 +-- src/Client/SingleClient.php | 100 +++---- src/Client/WorkerConfig.php | 12 +- src/Client/WorkerFiber.php | 8 +- src/Client/WorkerPackage.php | 6 +- src/Connection.php | 8 +- src/Encryption/TEA.php | 90 +++--- src/Exceptions/AccountFrozenException.php | 2 +- src/Exceptions/AccountsFrozenException.php | 2 +- src/Group.php | 8 +- src/Group/GroupId.php | 2 +- src/Internal/BinaryString.php | 4 +- src/Internal/MaybeBinaryString.php | 10 +- .../{AsyncClient.php => AsyncMMDBClient.php} | 46 ++-- src/MMDB/{Client.php => MMDBClient.php} | 2 +- src/MMDB/{Entry.php => MMDBEntry.php} | 2 +- src/Package.php | 38 +-- src/Package/In/AdmMuxInfo.php | 2 +- src/Package/In/BroadcastMessage.php | 2 +- src/Package/In/BuddyRemoved.php | 2 +- src/Package/In/BuddyState.php | 2 +- src/Package/In/CharacterLookupResult.php | 4 +- src/Package/In/CharacterName.php | 4 +- src/Package/In/CharacterUnknown.php | 2 +- src/Package/In/GroupJoined.php | 2 +- src/Package/In/GroupLeft.php | 2 +- src/Package/In/GroupMessage.php | 2 +- src/Package/In/LoginCharlist.php | 2 +- src/Package/In/LoginError.php | 2 +- src/Package/In/LoginOk.php | 2 +- src/Package/In/LoginSeed.php | 2 +- src/Package/In/Ping.php | 2 +- src/Package/In/PrivateChannelClientJoined.php | 2 +- src/Package/In/PrivateChannelClientLeft.php | 2 +- .../In/PrivateChannelInviteRefused.php | 2 +- src/Package/In/PrivateChannelInvited.php | 2 +- src/Package/In/PrivateChannelKicked.php | 2 +- src/Package/In/PrivateChannelLeft.php | 2 +- src/Package/In/PrivateChannelMessage.php | 2 +- src/Package/In/SimpleSystemMessage.php | 2 +- src/Package/In/SystemMessage.php | 2 +- src/Package/In/Tell.php | 2 +- src/Package/In/VicinityMessage.php | 2 +- src/Package/Out/BuddyAdd.php | 2 +- src/Package/Out/BuddyRemove.php | 2 +- src/Package/Out/CharacterLookup.php | 2 +- src/Package/Out/ChatCommand.php | 2 +- src/Package/Out/ClientmodeGet.php | 2 +- src/Package/Out/ClientmodeSet.php | 2 +- src/Package/Out/GroupDataSet.php | 2 +- src/Package/Out/GroupMessage.php | 2 +- src/Package/Out/GroupSetClientMode.php | 2 +- src/Package/Out/LoginRequest.php | 11 +- src/Package/Out/LoginSelectCharacter.php | 2 +- src/Package/Out/Pong.php | 2 +- src/Package/Out/PrivateChannelInvite.php | 2 +- src/Package/Out/PrivateChannelJoin.php | 2 +- src/Package/Out/PrivateChannelKick.php | 2 +- src/Package/Out/PrivateChannelKickAll.php | 2 +- src/Package/Out/PrivateChannelLeave.php | 2 +- src/Package/Out/PrivateChannelMessage.php | 2 +- src/Package/Out/SetOnlineStatus.php | 2 +- src/Package/Out/Tell.php | 2 +- src/Package/PackageType.php | 6 +- src/Parser.php | 142 +++++----- src/Tokenizer.php | 4 +- src/Utils.php | 10 +- tests/MMDBTest.php | 10 +- 75 files changed, 486 insertions(+), 686 deletions(-) create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .php-cs-fixer.php rename src/MMDB/{AsyncClient.php => AsyncMMDBClient.php} (74%) rename src/MMDB/{Client.php => MMDBClient.php} (90%) rename src/MMDB/{Entry.php => MMDBEntry.php} (84%) diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache index a32cb8b..872a69e 100644 --- a/.php-cs-fixer.cache +++ b/.php-cs-fixer.cache @@ -1 +1 @@ -{"php":"8.1.27","version":"3.51.0:v3.51.0#127fa74f010da99053e3f5b62672615b72dd6efd","indent":"\t","lineEnding":"\n","rules":{"align_multiline_comment":true,"assign_null_coalescing_to_coalesce_equal":true,"blank_line_after_namespace":true,"blank_line_before_statement":{"statements":["phpdoc"]},"array_syntax":{"syntax":"short"},"braces_position":{"allow_single_line_anonymous_functions":false,"allow_single_line_empty_anonymous_classes":false,"anonymous_classes_opening_brace":"same_line","anonymous_functions_opening_brace":"same_line","functions_opening_brace":"same_line","control_structures_opening_brace":"same_line","classes_opening_brace":"same_line"},"cast_spaces":{"space":"none"},"class_attributes_separation":{"elements":{"method":"one","case":"none"}},"class_definition":{"single_line":false,"space_before_parenthesis":true},"class_reference_name_casing":true,"clean_namespace":true,"combine_nested_dirname":true,"compact_nullable_type_declaration":true,"constant_case":{"case":"lower"},"control_structure_continuation_position":{"position":"same_line"},"declare_equal_normalize":{"space":"none"},"declare_parentheses":true,"declare_strict_types":true,"dir_constant":true,"elseif":true,"empty_loop_condition":{"style":"while"},"encoding":true,"explicit_indirect_variable":true,"explicit_string_variable":true,"full_opening_tag":true,"function_declaration":{"closure_function_spacing":"one","trailing_comma_single_line":false},"type_declaration_spaces":{"elements":["function"]},"group_import":true,"include":true,"integer_literal_case":true,"lambda_not_used_import":true,"line_ending":true,"list_syntax":{"syntax":"short"},"lowercase_static_reference":true,"lowercase_keywords":true,"lowercase_cast":true,"magic_constant_casing":true,"magic_method_casing":true,"method_argument_space":true,"multiline_comment_opening_closing":true,"multiline_whitespace_before_semicolons":true,"native_function_casing":true,"native_type_declaration_casing":true,"new_with_parentheses":true,"no_alternative_syntax":true,"no_blank_lines_after_class_opening":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_around_offset":{"positions":{"array":"inside"}},"spaces_inside_parentheses":{"space":"none"},"no_superfluous_phpdoc_tags":true,"no_trailing_comma_in_singleline":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"no_unneeded_control_parentheses":{"statements":["break","clone","continue","return","switch_case","yield"]},"no_unneeded_braces":{"namespaces":true},"no_unneeded_import_alias":true,"no_unreachable_default_argument_value":true,"no_unset_cast":true,"no_unused_imports":true,"no_useless_else":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"nullable_type_declaration_for_default_null_value":true,"object_operator_without_whitespace":true,"ordered_class_elements":{"order":["use_trait","constant_public","constant_protected","constant_private","property_public","property_protected","property_private","construct","destruct","magic","method_public","method_protected","method_private"]},"ordered_imports":{"imports_order":["const","function","class"],"sort_algorithm":"alpha"},"phpdoc_align":true,"phpdoc_indent":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_line_span":{"const":"single","method":"single","property":"single"},"phpdoc_no_empty_return":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_tag_casing":true,"phpdoc_trim":true,"phpdoc_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_var_annotation_correct_order":true,"phpdoc_var_without_name":true,"return_type_declaration":{"space_before":"none"},"short_scalar_cast":true,"simple_to_complex_string_variable":true,"simplified_null_return":true,"single_blank_line_at_eof":true,"blank_lines_before_namespace":{"max_line_breaks":2,"min_line_breaks":2},"single_class_element_per_statement":true,"single_line_after_imports":true,"single_line_comment_spacing":true,"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","attribute","break","case","catch","class","clone","comment","const","const_import","continue","do","else","elseif","enum","extends","final","finally","for","foreach","function","function_import","global","goto","if","implements","include","include_once","instanceof","insteadof","interface","match","named_argument","namespace","new","open_tag_with_echo","php_doc","php_open","private","protected","public","readonly","require","require_once","return","static","switch","throw","trait","try","use","use_lambda","use_trait","var","while","yield","yield_from"]},"standardize_not_equals":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"switch_continue_to_break":true,"ternary_operator_spaces":true,"ternary_to_null_coalescing":true,"trailing_comma_in_multiline":true,"trim_array_spaces":true,"types_spaces":{"space":"none","space_multiple_catch":"single"},"unary_operator_spaces":true,"visibility_required":true,"whitespace_after_comma_in_array":true},"hashes":{"src\/Package\/In\/AdmMuxInfo.php":"2a14d0878e80d6f443908e108f09ce00","src\/Package\/In\/BroadcastMessage.php":"70300cd878a4dbfb11af27dd882d2a1f","src\/Package\/In\/BuddyAdded.php":"f0652fdde2ed3e782b7dc36860ce4ee0","src\/Package\/In\/BuddyRemoved.php":"f3454040905b5bd3c5da990e3a78868a","src\/Package\/In\/CharacterLookupResult.php":"b7edb3b7e1149bebdc0b678d8d61afb5","src\/Package\/In\/CharacterName.php":"edcfcd51059d7701d4a7efd64ee63fa2","src\/Package\/In\/CharacterUnknown.php":"a363e249cec175c92544fb22ce1f3950","src\/Package\/In\/GroupJoined.php":"c01cf2556d7e14f35b0c5b0230df5500","src\/Package\/In\/GroupLeft.php":"077c560c6ebc23c9e8bad18906753198","src\/Package\/In\/GroupMessage.php":"16c0dcbd3ad0e5b157e4a578599a0230","src\/Package\/In\/LoginCharlist.php":"c77548d28eaf6e96fcf13199e2741fb0","src\/Package\/In\/LoginError.php":"fdc2b704ba49d56eea131a5f6b49595d","src\/Package\/In\/LoginOk.php":"1b0ef69bc46405a97e32d6fd8f33027e","src\/Package\/In\/LoginSeed.php":"d927e854ad7c33da6d717b1217452844","src\/Package\/In\/Ping.php":"5e2f892001c268e94044dd4a6cfcc3cf","src\/Package\/In\/PrivateChannelClientJoined.php":"5fe6a1af6c657893a586abb4cb8ebe88","src\/Package\/In\/PrivateChannelClientLeft.php":"8a4e3e47f626dfb856cec2ad7d0e755e","src\/Package\/In\/PrivateChannelInviteRefused.php":"f8ff1725ce584e1c065663e8a1ae4228","src\/Package\/In\/PrivateChannelInvited.php":"1469166edf7ca71373c03ae2f3b1b479","src\/Package\/In\/PrivateChannelKicked.php":"c7245462c80b63082dfaeb9dc4ff9f86","src\/Package\/In\/PrivateChannelLeft.php":"ae64505a1e1fc2062e864d85de3d3f4c","src\/Package\/In\/PrivateChannelMessage.php":"df2d0d6296d31f23e165511bd457816f","src\/Package\/In\/SimpleSystemMessage.php":"c33ef2a96acfe3f91b9084a35b5ee037","src\/Package\/In\/SystemMessage.php":"cfc7fcca72ef32e9d93d5ab7773dcd79","src\/Package\/In\/Tell.php":"cb0b401830b5fa70b016e9db56a9d2a0","src\/Package\/In\/VicinityMessage.php":"0a8756349628cd29b2ce56e57626ea81","src\/Package\/Attributes\/Param.php":"f4c865ba492ae63d19c8217bceae19ba","src\/Package\/Out\/BuddyAdd.php":"d0a5e69125c3225535c2dce7fe7de67e","src\/Package\/Out\/BuddyRemove.php":"b77a7efb8990849328c2432b5e8a5a96","src\/Package\/Out\/CharacterLookup.php":"a73fd0a54d145a41d9912ffcb95aeb18","src\/Package\/Out\/ChatCommand.php":"b379a66d0095eccc58b7d86a0f186614","src\/Package\/Out\/ClientmodeGet.php":"d105842fe526bf4d3e81a9430bfd9aad","src\/Package\/Out\/ClientmodeSet.php":"39d088069a5e7dd9538dec45c2303650","src\/Package\/Out\/GroupDataSet.php":"7efcbdf84b2da724999e95f1c50b1d6c","src\/Package\/Out\/GroupMessage.php":"b32669b8d4a90a5f4048bb40ddb37823","src\/Package\/Out\/GroupSetClientMode.php":"1bb6d151f6c73700b80ee56990ccd3e9","src\/Package\/Out\/LoginRequest.php":"f2686bbc8fc97b243aa3bd101d14b2d7","src\/Package\/Out\/LoginSelectCharacter.php":"7ecb5ed5b850ac4144b11b3eb51d23ec","src\/Package\/Out\/Pong.php":"4d4addda46339b7b8c66b349ea24c46d","src\/Package\/Out\/PrivateChannelInvite.php":"0962598c75ef2261b4a14e33d102bc74","src\/Package\/Out\/PrivateChannelJoin.php":"33543b7c1948b05fcc3a711ed7ef7b64","src\/Package\/Out\/PrivateChannelKick.php":"0bfc754732c47bbd2ebd0e06da9c933a","src\/Package\/Out\/PrivateChannelKickAll.php":"6b8fad100fc0adad6c329b98ed5e5ee6","src\/Package\/Out\/PrivateChannelLeave.php":"3ec29d344971c81f6272ecc922f0825d","src\/Package\/Out\/PrivateChannelMessage.php":"4b2880726ce2d84854ce077737ad630f","src\/Package\/Out\/RateLimited.php":"85340eb40cee48d0242ea4cd4643c819","src\/Package\/Out\/SetOnlineStatus.php":"e667b0120cdb9df2a00a6470810bc273","src\/Package\/Out\/Tell.php":"4c285a514c01fb7ad916685f12fc4cc9","src\/Package\/Type.php":"7de808122848d93d9757154971b255a9","src\/Package\/In.php":"e99c9a11c314d5cefe25d2ed11d40e0f","src\/Package\/Out.php":"fbb4449715b49b98f27f0950e0f058f7","src\/Tokenizer.php":"f0ab29d42e13ff74a552de27dcfeb078","src\/MMDB\/Entry.php":"9799277a7cdb7ec939653b96ffb9afd3","src\/MMDB\/AsyncClient.php":"127592567cc85a05c6a4adb3054da72c","src\/MMDB\/Client.php":"0f7fd913a3d3a43cf128f4e26bc41917","src\/LoginException.php":"9d10f524e341caeb7a7f0c33e4ec1fe8","src\/WrongPacketOrderException.php":"6674a1b975e21298736296cc52bbc2e6","src\/AccountFrozenException.php":"ca4fe044be1e1e70231c277b09f6e954","src\/CharacterNotFoundException.php":"ed3f99a0395c5d78263cba88df7ae35f","src\/BinaryPackage.php":"079b11e80f4093cb331ec23759b17840","src\/BinaryPackage\/In.php":"ae5471c65ee6e86e3eefb9a224a0bfe2","src\/BinaryPackage\/Out.php":"28aeb7b0d6352072c5dc45edba975e32","src\/Client\/WorkerConfig.php":"8ec22cc2889a8fd8e114f592db7821b6","src\/Client\/WorkerPackage.php":"13817da0a87251112dd4347267974b8e","src\/Client\/WorkerThread.php":"044c039a1ef9b7e8f4c624ab5d60eb49","src\/Client\/Statistics.php":"7bbadb881b55c63efd49f0b0e744b8e8","src\/Client\/Basic.php":"6a4954d1474cf37d3b64551bb4ad2138","src\/Client\/Multi.php":"1d98442cdca4cd2b1ef2f37f434c9328","src\/Connection.php":"aece6e9ef7cb59a5432dd382753b5094","src\/Encryption\/TEA.php":"2ef42d655f0c1e2c4060beb77c4277b1","src\/ExtendedMessage.php":"2c56db79ec9bc31f777f81a082f2181d","src\/Group.php":"05cf3fa22a19118afa45ea1594396c67","src\/Group\/Id.php":"0bcb0d75da11ba5132a7ab953359e196","src\/Group\/Type.php":"cd4d7d42a513d43c24ac7b60d7633064","src\/Internal\/BinaryString.php":"868eadb4fe9e67e8fc331533514aa104","src\/Internal\/MaybeBinaryString.php":"1f1f35578fdf15f2b69340bcb5c43552","src\/Package.php":"c5e5fb5e393937a3d684f4abb8b3d1e5","src\/Parser.php":"39a41882d31a0b2e0fe706192b004c41","src\/Utils.php":"dbd8cea796a59af3e33e9ff3e9998a16"}} \ No newline at end of file +{"php":"8.1.28","version":"3.51.0","indent":"\t","lineEnding":"\n","rules":{"align_multiline_comment":true,"assign_null_coalescing_to_coalesce_equal":true,"blank_line_after_namespace":true,"blank_line_before_statement":{"statements":["phpdoc"]},"array_syntax":{"syntax":"short"},"array_push":true,"braces_position":{"allow_single_line_anonymous_functions":false,"allow_single_line_empty_anonymous_classes":false,"anonymous_classes_opening_brace":"same_line","anonymous_functions_opening_brace":"same_line","functions_opening_brace":"same_line","control_structures_opening_brace":"same_line","classes_opening_brace":"same_line"},"cast_spaces":{"space":"none"},"class_attributes_separation":{"elements":{"method":"one","case":"none"}},"class_definition":{"single_line":false,"space_before_parenthesis":true},"class_reference_name_casing":true,"clean_namespace":true,"combine_nested_dirname":true,"compact_nullable_type_declaration":true,"constant_case":{"case":"lower"},"control_structure_continuation_position":{"position":"same_line"},"control_structure_braces":true,"declare_equal_normalize":{"space":"none"},"declare_parentheses":true,"declare_strict_types":true,"dir_constant":true,"elseif":true,"empty_loop_condition":{"style":"while"},"encoding":true,"explicit_indirect_variable":true,"explicit_string_variable":true,"full_opening_tag":true,"function_to_constant":{"functions":["get_called_class","get_class","get_class_this","php_sapi_name","phpversion","pi"]},"function_declaration":{"closure_fn_spacing":"one","closure_function_spacing":"one","trailing_comma_single_line":false},"type_declaration_spaces":{"elements":["function","property"]},"get_class_to_class_keyword":true,"group_import":true,"indentation_type":true,"include":true,"integer_literal_case":true,"lambda_not_used_import":true,"line_ending":true,"list_syntax":{"syntax":"short"},"lowercase_static_reference":true,"lowercase_keywords":true,"lowercase_cast":true,"magic_constant_casing":true,"magic_method_casing":true,"method_argument_space":{"attribute_placement":"same_line","keep_multiple_spaces_after_comma":false,"on_multiline":"ensure_fully_multiline"},"modernize_strpos":true,"modernize_types_casting":true,"multiline_comment_opening_closing":true,"multiline_whitespace_before_semicolons":true,"native_constant_invocation":true,"native_function_casing":true,"native_type_declaration_casing":true,"new_with_parentheses":true,"no_alias_functions":true,"no_alias_language_construct_call":true,"no_alternative_syntax":true,"no_blank_lines_after_class_opening":true,"no_closing_tag":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_multiple_statements_per_line":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"spaces_inside_parentheses":{"space":"none"},"no_spaces_around_offset":{"positions":{"array":"inside"}},"no_superfluous_phpdoc_tags":true,"no_trailing_comma_in_singleline":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"no_unneeded_control_parentheses":{"statements":["break","clone","continue","return","switch_case","yield"]},"no_unneeded_braces":{"namespaces":true},"no_unneeded_import_alias":true,"no_unreachable_default_argument_value":true,"no_unset_cast":true,"no_unused_imports":true,"no_useless_concat_operator":true,"no_useless_else":true,"no_useless_return":true,"no_useless_nullsafe_operator":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"nullable_type_declaration_for_default_null_value":true,"numeric_literal_separator":{"override_existing":false,"strategy":"use_separator"},"object_operator_without_whitespace":true,"operator_linebreak":{"only_booleans":true,"position":"beginning"},"ordered_class_elements":{"order":["use_trait","constant_public","constant_protected","constant_private","property_public","property_protected","property_private","construct","destruct","magic","method_public","method_protected","method_private"]},"ordered_imports":{"imports_order":["const","function","class"],"sort_algorithm":"alpha","case_sensitive":false},"ordered_types":{"case_sensitive":false,"null_adjustment":"always_first","sort_algorithm":"none"},"phpdoc_align":true,"phpdoc_indent":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_line_span":{"const":"single","method":"single","property":"single"},"phpdoc_no_empty_return":true,"phpdoc_param_order":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_tag_casing":true,"phpdoc_trim":true,"phpdoc_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_var_annotation_correct_order":true,"phpdoc_var_without_name":true,"psr_autoloading":true,"return_type_declaration":{"space_before":"none"},"short_scalar_cast":true,"simple_to_complex_string_variable":true,"simplified_if_return":true,"simplified_null_return":true,"single_blank_line_at_eof":true,"blank_lines_before_namespace":{"max_line_breaks":2,"min_line_breaks":2},"semicolon_after_instruction":true,"single_class_element_per_statement":true,"single_line_after_imports":true,"single_line_comment_spacing":true,"single_quote":true,"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","attribute","break","case","catch","class","clone","comment","const","const_import","continue","do","else","elseif","enum","extends","final","finally","for","foreach","function","function_import","global","goto","if","implements","include","include_once","instanceof","insteadof","interface","match","named_argument","namespace","new","open_tag_with_echo","php_doc","php_open","private","protected","public","readonly","require","require_once","return","static","switch","throw","trait","try","use","use_lambda","use_trait","var","while","yield","yield_from"]},"single_trait_insert_per_statement":true,"standardize_not_equals":true,"static_lambda":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"switch_continue_to_break":true,"ternary_operator_spaces":true,"ternary_to_null_coalescing":true,"ternary_to_elvis_operator":true,"trailing_comma_in_multiline":true,"trim_array_spaces":true,"types_spaces":{"space":"none","space_multiple_catch":"single"},"unary_operator_spaces":true,"visibility_required":true,"whitespace_after_comma_in_array":true},"hashes":{"src\/Package\/In\/AdmMuxInfo.php":"38de7c5073d016aafc2617777288e10e","src\/Package\/In\/BroadcastMessage.php":"22f54dd955f5059ff1927ca2086938c1","src\/Package\/In\/BuddyRemoved.php":"02af51ee16a7a11e6aa236bae980766d","src\/Package\/In\/CharacterLookupResult.php":"9fbf3303f2a8d5df6d3c7f1663acc777","src\/Package\/In\/CharacterName.php":"42a999cbf276a75be883a1f0b3d4509c","src\/Package\/In\/CharacterUnknown.php":"c6ecec79d555186da6c753adfbc84900","src\/Package\/In\/GroupJoined.php":"490950ade800d0dbedda0a2f1ff8b91e","src\/Package\/In\/GroupLeft.php":"47667ffa186078cea1ca29c3a0620383","src\/Package\/In\/GroupMessage.php":"50257b21c853e907de2471f4e5acb5a4","src\/Package\/In\/LoginCharlist.php":"de697a08eaff8c666ba7b1712d6c2c07","src\/Package\/In\/LoginError.php":"d9b972be10a665b2bad7b7b249a5daa6","src\/Package\/In\/LoginOk.php":"30dffa6fd6e0b8e147cf674cdb2f009f","src\/Package\/In\/LoginSeed.php":"8e77e426ab998a0a8ab04b7d79bb76fa","src\/Package\/In\/Ping.php":"9e93812ba75bc118e2f3559dca1dcc21","src\/Package\/In\/PrivateChannelClientJoined.php":"90b1dae6bbecebba80da1b55a224e6d6","src\/Package\/In\/PrivateChannelClientLeft.php":"cf048820456b2495dd7e3475b945662f","src\/Package\/In\/PrivateChannelInviteRefused.php":"516ee9b5035fb87f7d19542db475a6d7","src\/Package\/In\/PrivateChannelInvited.php":"b961cdc6d3b502f8fe609b0824158e3b","src\/Package\/In\/PrivateChannelKicked.php":"76768534859b4c7ccc34203fbdaddf37","src\/Package\/In\/PrivateChannelLeft.php":"1c4666b3f85f17fc6c109e707663bc54","src\/Package\/In\/PrivateChannelMessage.php":"c09ae8f3615fbffffc7e4cc3bb4e6fc9","src\/Package\/In\/SimpleSystemMessage.php":"efc882d08d104addc1362317a5ec023d","src\/Package\/In\/SystemMessage.php":"5f1e23bd4fe1959e47b466aed5594387","src\/Package\/In\/Tell.php":"ee659a699815c34e2fed6e6868822547","src\/Package\/In\/VicinityMessage.php":"843c8e3e44c504dbc74713dca22360cb","src\/Package\/In\/BuddyState.php":"619003a9324a1f3b7e00bd3d67b756e4","src\/Package\/Attributes\/Param.php":"f4c865ba492ae63d19c8217bceae19ba","src\/Package\/Out\/BuddyAdd.php":"affa08c510366517004a99d2eb1d0e16","src\/Package\/Out\/BuddyRemove.php":"9c35039b4facdf3a43d442ee4eb4b8c5","src\/Package\/Out\/CharacterLookup.php":"af30cc8de2537a1d570d4e214d87dfc6","src\/Package\/Out\/ChatCommand.php":"5412f4fee3046c599361bad2c76c8f43","src\/Package\/Out\/ClientmodeGet.php":"f9ec46e40285100e783bc31f6a9d961b","src\/Package\/Out\/ClientmodeSet.php":"ba3a2ee0b52b1f0b4202a8c0bcb72fc2","src\/Package\/Out\/GroupDataSet.php":"c04471b3968c61b2e73cdcb827175be4","src\/Package\/Out\/GroupMessage.php":"6531fef8debc242fe3e1e52eea10e365","src\/Package\/Out\/GroupSetClientMode.php":"fe473a7d148bda14af935f9b4fdcb293","src\/Package\/Out\/LoginRequest.php":"3281115137d1c43af578389a12536005","src\/Package\/Out\/LoginSelectCharacter.php":"4b98b111591b52e1b5d95a241e0d3b64","src\/Package\/Out\/Pong.php":"e0cbbed47caeb986f146862b31526d37","src\/Package\/Out\/PrivateChannelInvite.php":"a9673c4e1a8b19db554763eab41807d1","src\/Package\/Out\/PrivateChannelJoin.php":"cf180bb1b91e687a1843ca6109821f05","src\/Package\/Out\/PrivateChannelKick.php":"fb3c6406bd59c151ab03860e6b835477","src\/Package\/Out\/PrivateChannelKickAll.php":"130fb2570cbf92e6c5df320cecef6627","src\/Package\/Out\/PrivateChannelLeave.php":"feee3e9b351c84b73cd7b9eef12f546b","src\/Package\/Out\/PrivateChannelMessage.php":"6dc299eee00425665c68d761d9870d6e","src\/Package\/Out\/RateLimited.php":"ebec90ab508fa465ee986313b53a8549","src\/Package\/Out\/SetOnlineStatus.php":"a981f2d08029f154ba0a763aecd1bb51","src\/Package\/Out\/Tell.php":"465d5d8e042ebbdf457545529d92da0b","src\/Package\/InPackage.php":"1dbc9d84748851cf6febbdf178c1776d","src\/Package\/OutPackage.php":"363ce89cb0ed8c207159c2bc22ab7c3f","src\/Package\/PackageType.php":"a3060530373d7acce177b1ebddbc55cd","src\/Tokenizer.php":"b761dea3bccb03d18f55fa0e75ba3054","src\/MMDB\/Entry.php":"9799277a7cdb7ec939653b96ffb9afd3","src\/MMDB\/AsyncClient.php":"18c43e1542283361f2d4227f3d5f1c56","src\/MMDB\/Client.php":"0f7fd913a3d3a43cf128f4e26bc41917","src\/BinaryPackage.php":"d709137aadf296654b0d7920509878d2","src\/BinaryPackage\/BinaryPackageIn.php":"1060050308ba3a8557e82bb8601cd131","src\/BinaryPackage\/BinaryPackageOut.php":"cc2ff92e11820c8865a8defd9e3a4587","src\/Client\/Statistics.php":"cc0feb38a45db60a7957de98841fcf2a","src\/Client\/WorkerConfig.php":"3e4191d6539052fe1abc560262bdd12c","src\/Client\/WorkerPackage.php":"f62cf3cda03988b5048ae6efd268f02a","src\/Client\/SingleClient.php":"6b0c2d9d9eb496f562a0c8551083b7b5","src\/Client\/MultiClient.php":"a3862aad2e1e5342e92d1d6ef9ab9d32","src\/Client\/WorkerFiber.php":"7c902aa54550c1a26e3c305370c48b50","src\/Encryption\/TEA.php":"6eb4b65a3136796583e7b7daaf841b5b","src\/ExtendedMessage.php":"2c56db79ec9bc31f777f81a082f2181d","src\/Group\/GroupId.php":"88c90a2991227c23c2ca44142ec87741","src\/Group\/GroupType.php":"d55748d7f1d6c6bf502c6f0ef6326be6","src\/Internal\/BinaryString.php":"640da2ee3c28cb52b7710872ecb3e75d","src\/Internal\/MaybeBinaryString.php":"1073378fdee1b2ba5eca9ae98ffedb0b","src\/Parser.php":"33afc469735ac29d095bde601ffd1d03","src\/Utils.php":"707337159bfda308d1875c2147672354","src\/AccountUnfreezer.php":"6615f2add1f0cfa04e37271b8cf19cb9","src\/Package.php":"40d2501082bda3e74238b62e93cf1007","src\/Group.php":"543470bda9ccc4616a41bc73affe6219","src\/Connection.php":"ac72c4c02eb5457c0500892b4c11b325","src\/Exceptions\/LoginException.php":"e89cea1e1440bae0feb2e36acc7f4845","src\/Exceptions\/AccountFrozenException.php":"4420d18bdd4ab966f3e3aee6d344468f","src\/Exceptions\/CharacterNotFoundException.php":"50b2d9a69510dc5a2d64b18dac7705bd","src\/Exceptions\/WrongPacketOrderException.php":"a201de8f109eea279bd282609603a4e8","src\/Exceptions\/AccountsFrozenException.php":"81d2eb4a781c5f65e97f1595d1c86f7c","src\/FrozenAccount.php":"dc334b13bfa89cfc9be048160bbf8b98"}} \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..c626dcf --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,12 @@ +getFinder() + ->in(__DIR__ . '/src'); + +$config->setCacheFile(__DIR__ . '/.php-cs-fixer.cache'); + +return $config; diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php deleted file mode 100644 index 538d231..0000000 --- a/.php-cs-fixer.php +++ /dev/null @@ -1,258 +0,0 @@ -in('src'); - -$config = new PhpCsFixer\Config(); -return $config - ->setIndent("\t") - ->setRules([ - 'align_multiline_comment' => true, - 'assign_null_coalescing_to_coalesce_equal' => true, - 'blank_line_after_namespace' => true, - 'blank_line_before_statement' => [ - 'statements' => [ - 'phpdoc', - ], - ], - 'array_syntax' => ['syntax' => 'short'], - 'braces_position' => [ - 'allow_single_line_anonymous_functions' => false, - 'allow_single_line_empty_anonymous_classes' => false, - 'anonymous_classes_opening_brace' => 'same_line', - 'anonymous_functions_opening_brace' => 'same_line', - 'functions_opening_brace' => 'same_line', - 'control_structures_opening_brace' => 'same_line', - 'classes_opening_brace' => 'same_line', - ], - 'cast_spaces' => ['space' => 'none'], - 'class_attributes_separation' => ['elements' => [ -// 'const' => 'none', - 'method' => 'one', -// 'trait_import' => 'none', - 'case' => 'none', -// 'property' => 'one', - ]], - 'class_definition' => [ - 'single_line' => false, -// 'single_line' => true, - 'space_before_parenthesis' => true, -// 'space_before_parenthesis' => false, - ], - 'class_reference_name_casing' => true, - 'clean_namespace' => true, - 'combine_consecutive_issets' => false, - 'combine_consecutive_unsets' => false, - 'combine_nested_dirname' => true, - 'compact_nullable_type_declaration' => true, -// 'concat_space' => ['spacing' => 'one'], - 'constant_case' => ['case' => 'lower'], - 'control_structure_continuation_position' => ['position' => 'same_line'], - 'declare_equal_normalize' => ['space' => 'none'], - 'declare_parentheses' => true, - 'declare_strict_types' => true, - 'dir_constant' => true, - 'elseif' => true, - 'empty_loop_condition' => ['style' => 'while'], - 'encoding' => true, - 'string_implicit_backslashes' => false, - 'explicit_indirect_variable' => true, - 'explicit_string_variable' => true, - 'full_opening_tag' => true, -// 'fully_qualified_strict_types' => true, - 'function_declaration' => [ -// 'closure_function_spacing' => 'none', - 'closure_function_spacing' => 'one', - 'trailing_comma_single_line' => false, - ], - 'type_declaration_spaces' => ['elements' => ['function']], - 'group_import' => true, - 'include' => true, - 'integer_literal_case' => true, - 'lambda_not_used_import' => true, - 'line_ending' => true, - 'list_syntax' => ['syntax' => 'short'], - 'lowercase_static_reference' => true, - 'lowercase_keywords' => true, - 'lowercase_cast' => true, - 'magic_constant_casing' => true, - 'magic_method_casing' => true, - 'method_argument_space' => true, -// 'method_chaining_indentation' => true, - 'multiline_comment_opening_closing' => true, - 'multiline_whitespace_before_semicolons' => true, - 'native_function_casing' => true, - 'native_type_declaration_casing' => true, - 'new_with_parentheses' => true, - 'no_alternative_syntax' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_leading_import_slash' => true, -// 'no_multiline_whitespace_around_double_arrow' => true, - 'no_leading_namespace_whitespace' => true, - 'no_short_bool_cast' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_space_around_double_colon' => true, - 'no_spaces_after_function_name' => true, - 'no_spaces_around_offset' => ['positions' => ['array' => 'inside']], - 'spaces_inside_parentheses' => ['space' => 'none'], -// 'no_superfluous_elseif' => true, - 'no_superfluous_phpdoc_tags' => true, - 'no_trailing_comma_in_singleline' => true, - 'no_trailing_whitespace' => true, - 'no_trailing_whitespace_in_comment' => true, - 'no_unneeded_control_parentheses' => [ - 'statements' => [ - 'break', - 'clone', - 'continue', - 'return', - 'switch_case', - 'yield', - ], - ], - 'no_unneeded_braces' => ['namespaces' => true], - 'no_unneeded_import_alias' => true, - 'no_unreachable_default_argument_value' => true, - 'no_unset_cast' => true, - 'no_unused_imports' => true, - 'no_useless_else' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - 'normalize_index_brace' => true, - 'nullable_type_declaration_for_default_null_value' => true, - 'object_operator_without_whitespace' => true, -// 'operator_linebreak' => true, - 'ordered_class_elements' => [ - 'order' => [ - 'use_trait', - 'constant_public', - 'constant_protected', - 'constant_private', - 'property_public', - 'property_protected', - 'property_private', - 'construct', - 'destruct', - 'magic', - 'method_public', - 'method_protected', - 'method_private', - ], - ], - 'ordered_imports' => [ - 'imports_order' => ['const', 'function', 'class'], - 'sort_algorithm' => 'alpha', - ], - 'phpdoc_align' => true, - 'phpdoc_indent' => true, - 'phpdoc_inline_tag_normalizer' => true, - 'phpdoc_line_span' => [ - 'const' => 'single', - 'method' => 'single', - 'property' => 'single', - ], - 'phpdoc_no_empty_return' => true, - 'phpdoc_scalar' => true, - 'phpdoc_separation' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_tag_casing' => true, - 'phpdoc_trim' => true, - 'phpdoc_trim_consecutive_blank_line_separation' => true, - 'phpdoc_types' => true, - 'phpdoc_var_annotation_correct_order' => true, - 'phpdoc_var_without_name' => true, - 'return_type_declaration' => ['space_before' => 'none'], - 'short_scalar_cast' => true, - 'simple_to_complex_string_variable' => true, - 'simplified_null_return' => true, - 'single_blank_line_at_eof' => true, - 'blank_lines_before_namespace' => ['max_line_breaks' => 2, 'min_line_breaks' => 2], - 'single_class_element_per_statement' => true, -// 'single_import_per_statement' => true, - 'single_line_after_imports' => true, - 'single_line_comment_spacing' => true, -// 'single_quote' => true, - 'single_space_around_construct' => [ - 'constructs_followed_by_a_single_space' => [ - 'abstract', - 'as', - 'attribute', - 'break', - 'case', - 'catch', - 'class', - 'clone', - 'comment', - 'const', - 'const_import', - 'continue', - 'do', - 'else', - 'elseif', - 'enum', - 'extends', - 'final', - 'finally', - 'for', - 'foreach', - 'function', - 'function_import', - 'global', - 'goto', - 'if', - 'implements', - 'include', - 'include_once', - 'instanceof', - 'insteadof', - 'interface', - 'match', - 'named_argument', - 'namespace', - 'new', - 'open_tag_with_echo', - 'php_doc', - 'php_open', - 'private', - 'protected', - 'public', - 'readonly', - 'require', - 'require_once', - 'return', - 'static', - 'switch', - 'throw', - 'trait', - 'try', - 'use', - 'use_lambda', - 'use_trait', - 'var', - 'while', - 'yield', - 'yield_from', - - ], - ], - 'standardize_not_equals' => true, - 'switch_case_semicolon_to_colon' => true, - 'switch_case_space' => true, - 'switch_continue_to_break' => true, - 'ternary_operator_spaces' => true, - 'ternary_to_null_coalescing' => true, - 'trailing_comma_in_multiline' => true, - 'trim_array_spaces' => true, - 'types_spaces' => [ - 'space' => 'none', - 'space_multiple_catch' => 'single', - ], - 'unary_operator_spaces' => true, - 'visibility_required' => true, - 'whitespace_after_comma_in_array' => true, - ]) - ->setRiskyAllowed(true) - ->setFinder($finder); diff --git a/.vscode/settings.json b/.vscode/settings.json index 53f6dd3..038c995 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "simple-php-cs-fixer.config": ".php-cs-fixer.php", + "simple-php-cs-fixer.config": ".php-cs-fixer.dist.php", "simple-php-cs-fixer.executablePath": "vendor/bin/php-cs-fixer.phar", "simple-php-cs-fixer.save": true, "simple-php-cs-fixer.useConfig": true, diff --git a/composer.json b/composer.json index fcecc0e..58232a3 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,10 @@ } }, "repositories": [ + { + "type": "git", + "url": "https://github.com/Nadybot/Nadystyle.git" + }, { "type": "git", "url": "https://github.com/Nadybot/leaky-bucket.git" @@ -33,6 +37,7 @@ ], "require-dev": { + "nadybot/nadystyle": "dev-main", "composer-phar/php-cs-fixer": "^3.51.0", "squizlabs/php_codesniffer": "^3.8", "composer-phar/phpstan": "^1.10", diff --git a/composer.lock b/composer.lock index 88a2547..c31f553 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ede3ebf98fcdbe1ddd9b605043d83aaa", + "content-hash": "84962ccd6ec486fcf093b210ba43d342", "packages": [ { "name": "amphp/amp", @@ -402,21 +402,22 @@ }, { "name": "amphp/parallel", - "version": "v2.2.6", + "version": "v2.2.9", "source": { "type": "git", "url": "https://github.com/amphp/parallel.git", - "reference": "5aeaad20297507cc754859236720501b54306eba" + "reference": "73d293f1fc4df1bebc3c4fce1432e82dd7032238" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/parallel/zipball/5aeaad20297507cc754859236720501b54306eba", - "reference": "5aeaad20297507cc754859236720501b54306eba", + "url": "https://api.github.com/repos/amphp/parallel/zipball/73d293f1fc4df1bebc3c4fce1432e82dd7032238", + "reference": "73d293f1fc4df1bebc3c4fce1432e82dd7032238", "shasum": "" }, "require": { "amphp/amp": "^3", "amphp/byte-stream": "^2", + "amphp/cache": "^2", "amphp/parser": "^1", "amphp/pipeline": "^1", "amphp/process": "^2", @@ -473,7 +474,7 @@ ], "support": { "issues": "https://github.com/amphp/parallel/issues", - "source": "https://github.com/amphp/parallel/tree/v2.2.6" + "source": "https://github.com/amphp/parallel/tree/v2.2.9" }, "funding": [ { @@ -481,20 +482,20 @@ "type": "github" } ], - "time": "2024-01-07T18:12:13+00:00" + "time": "2024-03-24T18:27:44+00:00" }, { "name": "amphp/parser", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/amphp/parser.git", - "reference": "ff1de4144726c5dad5fab97f66692ebe8de3e151" + "reference": "3cf1f8b32a0171d4b1bed93d25617637a77cded7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/parser/zipball/ff1de4144726c5dad5fab97f66692ebe8de3e151", - "reference": "ff1de4144726c5dad5fab97f66692ebe8de3e151", + "url": "https://api.github.com/repos/amphp/parser/zipball/3cf1f8b32a0171d4b1bed93d25617637a77cded7", + "reference": "3cf1f8b32a0171d4b1bed93d25617637a77cded7", "shasum": "" }, "require": { @@ -535,7 +536,7 @@ ], "support": { "issues": "https://github.com/amphp/parser/issues", - "source": "https://github.com/amphp/parser/tree/v1.1.0" + "source": "https://github.com/amphp/parser/tree/v1.1.1" }, "funding": [ { @@ -543,20 +544,20 @@ "type": "github" } ], - "time": "2022-12-30T18:08:47+00:00" + "time": "2024-03-21T19:16:53+00:00" }, { "name": "amphp/pipeline", - "version": "v1.1.0", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/amphp/pipeline.git", - "reference": "8a0ecc281bb0932d6b4a786453aff18c55756e63" + "reference": "f1c2ce35d27ae86ead018adb803eccca7421dd9b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/pipeline/zipball/8a0ecc281bb0932d6b4a786453aff18c55756e63", - "reference": "8a0ecc281bb0932d6b4a786453aff18c55756e63", + "url": "https://api.github.com/repos/amphp/pipeline/zipball/f1c2ce35d27ae86ead018adb803eccca7421dd9b", + "reference": "f1c2ce35d27ae86ead018adb803eccca7421dd9b", "shasum": "" }, "require": { @@ -602,7 +603,7 @@ ], "support": { "issues": "https://github.com/amphp/pipeline/issues", - "source": "https://github.com/amphp/pipeline/tree/v1.1.0" + "source": "https://github.com/amphp/pipeline/tree/v1.2.0" }, "funding": [ { @@ -610,7 +611,7 @@ "type": "github" } ], - "time": "2023-12-23T04:34:28+00:00" + "time": "2024-03-10T14:48:16+00:00" }, { "name": "amphp/process", @@ -740,16 +741,16 @@ }, { "name": "amphp/socket", - "version": "v2.2.4", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/amphp/socket.git", - "reference": "4223324c627cc26d44800630411e64856d3344bc" + "reference": "acc0a2f65ab498025ba5641f7cce499c4b1ed4b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/socket/zipball/4223324c627cc26d44800630411e64856d3344bc", - "reference": "4223324c627cc26d44800630411e64856d3344bc", + "url": "https://api.github.com/repos/amphp/socket/zipball/acc0a2f65ab498025ba5641f7cce499c4b1ed4b5", + "reference": "acc0a2f65ab498025ba5641f7cce499c4b1ed4b5", "shasum": "" }, "require": { @@ -812,7 +813,7 @@ ], "support": { "issues": "https://github.com/amphp/socket/issues", - "source": "https://github.com/amphp/socket/tree/v2.2.4" + "source": "https://github.com/amphp/socket/tree/v2.3.0" }, "funding": [ { @@ -820,20 +821,20 @@ "type": "github" } ], - "time": "2024-02-28T15:56:06+00:00" + "time": "2024-03-19T20:01:53+00:00" }, { "name": "amphp/sync", - "version": "v2.1.0", + "version": "v2.2.0", "source": { "type": "git", "url": "https://github.com/amphp/sync.git", - "reference": "50ddc7392cc8034b3e4798cef3cc90d3f4c0441c" + "reference": "375ef5b54a0d12c38e12728dde05a55e30f2fbec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/sync/zipball/50ddc7392cc8034b3e4798cef3cc90d3f4c0441c", - "reference": "50ddc7392cc8034b3e4798cef3cc90d3f4c0441c", + "url": "https://api.github.com/repos/amphp/sync/zipball/375ef5b54a0d12c38e12728dde05a55e30f2fbec", + "reference": "375ef5b54a0d12c38e12728dde05a55e30f2fbec", "shasum": "" }, "require": { @@ -847,7 +848,7 @@ "amphp/php-cs-fixer-config": "^2", "amphp/phpunit-util": "^3", "phpunit/phpunit": "^9", - "psalm/phar": "^5.4" + "psalm/phar": "5.23" }, "type": "library", "autoload": { @@ -887,7 +888,7 @@ ], "support": { "issues": "https://github.com/amphp/sync/issues", - "source": "https://github.com/amphp/sync/tree/v2.1.0" + "source": "https://github.com/amphp/sync/tree/v2.2.0" }, "funding": [ { @@ -895,7 +896,7 @@ "type": "github" } ], - "time": "2023-08-19T13:53:40+00:00" + "time": "2024-03-12T01:00:01+00:00" }, { "name": "amphp/windows-registry", @@ -1053,16 +1054,16 @@ }, { "name": "league/uri", - "version": "7.4.0", + "version": "7.4.1", "source": { "type": "git", "url": "https://github.com/thephpleague/uri.git", - "reference": "bf414ba956d902f5d98bf9385fcf63954f09dce5" + "reference": "bedb6e55eff0c933668addaa7efa1e1f2c417cc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/uri/zipball/bf414ba956d902f5d98bf9385fcf63954f09dce5", - "reference": "bf414ba956d902f5d98bf9385fcf63954f09dce5", + "url": "https://api.github.com/repos/thephpleague/uri/zipball/bedb6e55eff0c933668addaa7efa1e1f2c417cc4", + "reference": "bedb6e55eff0c933668addaa7efa1e1f2c417cc4", "shasum": "" }, "require": { @@ -1131,7 +1132,7 @@ "docs": "https://uri.thephpleague.com", "forum": "https://thephpleague.slack.com", "issues": "https://github.com/thephpleague/uri-src/issues", - "source": "https://github.com/thephpleague/uri/tree/7.4.0" + "source": "https://github.com/thephpleague/uri/tree/7.4.1" }, "funding": [ { @@ -1139,20 +1140,20 @@ "type": "github" } ], - "time": "2023-12-01T06:24:25+00:00" + "time": "2024-03-23T07:42:40+00:00" }, { "name": "league/uri-interfaces", - "version": "7.4.0", + "version": "7.4.1", "source": { "type": "git", "url": "https://github.com/thephpleague/uri-interfaces.git", - "reference": "bd8c487ec236930f7bbc42b8d374fa882fbba0f3" + "reference": "8d43ef5c841032c87e2de015972c06f3865ef718" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/bd8c487ec236930f7bbc42b8d374fa882fbba0f3", - "reference": "bd8c487ec236930f7bbc42b8d374fa882fbba0f3", + "url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/8d43ef5c841032c87e2de015972c06f3865ef718", + "reference": "8d43ef5c841032c87e2de015972c06f3865ef718", "shasum": "" }, "require": { @@ -1215,7 +1216,7 @@ "docs": "https://uri.thephpleague.com", "forum": "https://thephpleague.slack.com", "issues": "https://github.com/thephpleague/uri-src/issues", - "source": "https://github.com/thephpleague/uri-interfaces/tree/7.4.0" + "source": "https://github.com/thephpleague/uri-interfaces/tree/7.4.1" }, "funding": [ { @@ -1223,7 +1224,7 @@ "type": "github" } ], - "time": "2023-11-24T15:40:42+00:00" + "time": "2024-03-23T07:42:40+00:00" }, { "name": "nadylib/leaky-bucket", @@ -1825,18 +1826,53 @@ ], "time": "2023-03-08T13:26:56+00:00" }, + { + "name": "nadybot/nadystyle", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/Nadybot/Nadystyle.git", + "reference": "53b299fca4970fe06af92ccd02865015acac7a13" + }, + "require": { + "composer-phar/php-cs-fixer": "^3.51.0", + "php": ">=8.1.17", + "squizlabs/php_codesniffer": "^3.8" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "Nadystyle\\": "src", + "PHP_CodeSniffer\\Standards\\": "style" + } + }, + "license": [ + "AGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Nadyita", + "email": "nadyita@hodorraid.org", + "homepage": "https://nadybot.org", + "role": "Developer" + } + ], + "description": "Code style configuration for all Nadybot PHP projects", + "time": "2024-04-13T07:20:53+00:00" + }, { "name": "nikic/php-parser", - "version": "v5.0.1", + "version": "v5.0.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "2218c2252c874a4624ab2f613d86ac32d227bc69" + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/2218c2252c874a4624ab2f613d86ac32d227bc69", - "reference": "2218c2252c874a4624ab2f613d86ac32d227bc69", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", "shasum": "" }, "require": { @@ -1879,26 +1915,27 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" }, - "time": "2024-02-21T19:24:10+00:00" + "time": "2024-03-05T20:51:40+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + "reference": "54750ef60c58e43759730615a392c31c80e23176" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", "shasum": "" }, "require": { "ext-dom": "*", + "ext-libxml": "*", "ext-phar": "*", "ext-xmlwriter": "*", "phar-io/version": "^3.0.1", @@ -1939,9 +1976,15 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/2.0.3" + "source": "https://github.com/phar-io/manifest/tree/2.0.4" }, - "time": "2021-07-20T11:28:43+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" }, { "name": "phar-io/version", @@ -1996,16 +2039,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.59", + "version": "1.10.66", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e607609388d3a6d418a50a49f7940e8086798281" + "reference": "94779c987e4ebd620025d9e5fdd23323903950bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e607609388d3a6d418a50a49f7940e8086798281", - "reference": "e607609388d3a6d418a50a49f7940e8086798281", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/94779c987e4ebd620025d9e5fdd23323903950bd", + "reference": "94779c987e4ebd620025d9e5fdd23323903950bd", "shasum": "" }, "require": { @@ -2054,20 +2097,20 @@ "type": "tidelift" } ], - "time": "2024-02-20T13:59:13+00:00" + "time": "2024-03-28T16:17:31+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "10.1.12", + "version": "10.1.14", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "842f72662d6b9edda84c4b6f13885fd9cd53dc63" + "reference": "e3f51450ebffe8e0efdf7346ae966a656f7d5e5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/842f72662d6b9edda84c4b6f13885fd9cd53dc63", - "reference": "842f72662d6b9edda84c4b6f13885fd9cd53dc63", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/e3f51450ebffe8e0efdf7346ae966a656f7d5e5b", + "reference": "e3f51450ebffe8e0efdf7346ae966a656f7d5e5b", "shasum": "" }, "require": { @@ -2124,7 +2167,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.12" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.14" }, "funding": [ { @@ -2132,7 +2175,7 @@ "type": "github" } ], - "time": "2024-03-02T07:22:05+00:00" + "time": "2024-03-12T15:33:41+00:00" }, { "name": "phpunit/php-file-iterator", @@ -2379,16 +2422,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.11", + "version": "10.5.17", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "0d968f6323deb3dbfeba5bfd4929b9415eb7a9a4" + "reference": "c1f736a473d21957ead7e94fcc029f571895abf5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0d968f6323deb3dbfeba5bfd4929b9415eb7a9a4", - "reference": "0d968f6323deb3dbfeba5bfd4929b9415eb7a9a4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c1f736a473d21957ead7e94fcc029f571895abf5", + "reference": "c1f736a473d21957ead7e94fcc029f571895abf5", "shasum": "" }, "require": { @@ -2460,7 +2503,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.11" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.17" }, "funding": [ { @@ -2476,7 +2519,7 @@ "type": "tidelift" } ], - "time": "2024-02-25T14:05:00+00:00" + "time": "2024-04-05T04:39:01+00:00" }, { "name": "sebastian/cli-parser", @@ -2850,16 +2893,16 @@ }, { "name": "sebastian/environment", - "version": "6.0.1", + "version": "6.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951" + "reference": "8074dbcd93529b357029f5cc5058fd3e43666984" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/43c751b41d74f96cbbd4e07b7aec9675651e2951", - "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984", + "reference": "8074dbcd93529b357029f5cc5058fd3e43666984", "shasum": "" }, "require": { @@ -2874,7 +2917,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "6.0-dev" + "dev-main": "6.1-dev" } }, "autoload": { @@ -2902,7 +2945,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", "security": "https://github.com/sebastianbergmann/environment/security/policy", - "source": "https://github.com/sebastianbergmann/environment/tree/6.0.1" + "source": "https://github.com/sebastianbergmann/environment/tree/6.1.0" }, "funding": [ { @@ -2910,7 +2953,7 @@ "type": "github" } ], - "time": "2023-04-11T05:39:26+00:00" + "time": "2024-03-23T08:47:14+00:00" }, { "name": "sebastian/exporter", @@ -3396,16 +3439,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.9.0", + "version": "3.9.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" + "reference": "267a4405fff1d9c847134db3a3c92f1ab7f77909" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", - "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/267a4405fff1d9c847134db3a3c92f1ab7f77909", + "reference": "267a4405fff1d9c847134db3a3c92f1ab7f77909", "shasum": "" }, "require": { @@ -3472,7 +3515,7 @@ "type": "open_collective" } ], - "time": "2024-02-16T15:06:51+00:00" + "time": "2024-03-31T21:03:09+00:00" }, { "name": "thecodingmachine/phpstan-safe-rule", @@ -3533,16 +3576,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.2", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96" + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b2ad5003ca10d4ee50a12da31de12a5774ba6b96", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", "shasum": "" }, "require": { @@ -3571,7 +3614,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.2" + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" }, "funding": [ { @@ -3579,13 +3622,14 @@ "type": "github" } ], - "time": "2023-11-20T00:12:19+00:00" + "time": "2024-03-03T12:36:25+00:00" } ], "aliases": [], "minimum-stability": "stable", "stability-flags": { - "nadylib/leaky-bucket": 20 + "nadylib/leaky-bucket": 20, + "nadybot/nadystyle": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/src/BinaryPackage.php b/src/BinaryPackage.php index 213b14f..5c95127 100644 --- a/src/BinaryPackage.php +++ b/src/BinaryPackage.php @@ -12,12 +12,12 @@ class BinaryPackage implements Stringable { final public function __construct( public readonly PackageType $type, public readonly int $length, - public readonly string $body="", + public readonly string $body='', ) { } public function __toString(): string { - $classes = explode("\\", get_class($this)); + $classes = explode('\\', static::class); $class = array_pop($classes); $body = (string)(new BinaryString($this->body)); return "<{$class}>{". @@ -27,11 +27,11 @@ public function __toString(): string { } public function toBinary(): string { - return pack("nn", $this->type->value, $this->length) . $this->body; + return pack('nn', $this->type->value, $this->length) . $this->body; } public static function fromBinary(string $binary): self { - $header = unpack("ntype/nlength", $binary); + $header = unpack('ntype/nlength', $binary); assert(is_int($header['length'])); assert($header['length'] >= 0); $binBody = substr($binary, 4); diff --git a/src/Client/MultiClient.php b/src/Client/MultiClient.php index dd36386..27042a2 100644 --- a/src/Client/MultiClient.php +++ b/src/Client/MultiClient.php @@ -54,11 +54,11 @@ public function __construct( $this->readQueue = new Queue(0); // @phpstan-ignore-next-line if (empty($workers)) { - throw new InvalidArgumentException(__CLASS__ . "::" . __FUNCTION__ . "(\$workers\) must me non-empty"); + throw new InvalidArgumentException(__CLASS__ . '::' . __FUNCTION__ . "(\$workers\) must me non-empty"); } foreach ($workers as $key => $workerConfig) { if (!($workerConfig instanceof WorkerConfig)) { - throw new InvalidArgumentException(__CLASS__ . "::" . __FUNCTION__ . "(\$workers[\$key\]\) is not a WorkerConfig"); + throw new InvalidArgumentException(__CLASS__ . '::' . __FUNCTION__ . "(\$workers[\$key\]\) is not a WorkerConfig"); } $this->configs []= $workerConfig; } @@ -134,7 +134,7 @@ public function onReady(Closure $callback): void { public function getStatistics(): Statistics { return array_reduce( $this->connections, - function (Statistics $stats, SingleClient $client): Statistics { + static function (Statistics $stats, SingleClient $client): Statistics { return $stats->add($client->getStatistics()); }, new Statistics() @@ -172,7 +172,7 @@ public function login(): void { } throw new AccountsFrozenException(accounts: $frozenAccounts); } - $this->logger?->notice("All workers logged in successfully."); + $this->logger?->notice('All workers logged in successfully.'); $numReady = 0; foreach ($workers[1] as $worker) { $this->connections[$worker->config->character] = $worker->client; @@ -325,18 +325,18 @@ public function getBestWorker(?string $worker=null): ?SingleClient { protected function triggerOnReady(): void { $this->isReady = true; - $this->logger?->notice("Bot is now fully ready"); + $this->logger?->notice('Bot is now fully ready'); while (null !== ($callback = array_shift($this->readyListeners))) { - $this->logger?->debug("Calling {closure}", [ - "closure" => Utils::closureToString($callback), + $this->logger?->debug('Calling {closure}', [ + 'closure' => Utils::closureToString($callback), ]); try { $callback(); } catch (Throwable $e) { - $this->logger?->error("Error calling {closure}: {error}", [ - "closure" => Utils::closureToString($callback), - "error" => $e->getMessage(), - "exception" => $e, + $this->logger?->error('Error calling {closure}: {error}', [ + 'closure' => Utils::closureToString($callback), + 'error' => $e->getMessage(), + 'exception' => $e, ]); } } @@ -360,20 +360,20 @@ private function workerLoop(WorkerFiber $worker): void { private function clientLogin(WorkerConfig $config): WorkerFiber { do { - $this->logger?->notice("Connecting to server {server}", ["server" => $config->getServer()]); + $this->logger?->notice('Connecting to server {server}', ['server' => $config->getServer()]); try { $connection = connect($config->getServer()); } catch (\Throwable $e) { - $this->logger?->error("Cannot connect to {server}: {error}. Retrying in {delay}s", [ - "server" => $config->getServer(), - "error" => $e->getMessage(), - "delay" => 5, - "exception" => $e, + $this->logger?->error('Cannot connect to {server}: {error}. Retrying in {delay}s', [ + 'server' => $config->getServer(), + 'error' => $e->getMessage(), + 'delay' => 5, + 'exception' => $e, ]); delay(5); } } while (!isset($connection)); - $this->logger?->info("Connected to {server}", ["server" => $config->getServer()]); + $this->logger?->info('Connected to {server}', ['server' => $config->getServer()]); $client = new SingleClient( logger: $this->logger, parser: $this->parser ?? Parser::createDefault(), @@ -389,8 +389,8 @@ private function clientLogin(WorkerConfig $config): WorkerFiber { password: $config->password, character: Utils::normalizeCharacter($config->character), ); - $this->logger?->notice("Successfully logged in {character}", [ - "character" => $config->character, + $this->logger?->notice('Successfully logged in {character}', [ + 'character' => $config->character, ]); return new WorkerFiber( config: $config, diff --git a/src/Client/SingleClient.php b/src/Client/SingleClient.php index b465336..eb56eb7 100644 --- a/src/Client/SingleClient.php +++ b/src/Client/SingleClient.php @@ -27,7 +27,7 @@ use Throwable; class SingleClient { - public const UID_NONE = 0xFFFFFFFF; + public const UID_NONE = 0xFF_FF_FF_FF; /** @var array */ private array $uidToName = []; @@ -170,8 +170,8 @@ public function lookupCharacter(int $uid, bool $cacheOnly=false): ?string { return $character; } $this->write(new Out\BuddyAdd(charId: $uid)); - unset($this->nameToUid["X"]); - $this->lookupUid("X"); + unset($this->nameToUid['X']); + $this->lookupUid('X'); $this->write(new Out\BuddyRemove(charId: $uid)); return $this->uidToName[$uid] ?? null; } @@ -239,7 +239,7 @@ public function isOnline(int $uid, bool $cacheOnly=true): ?bool { public function read(): ?Package\InPackage { $binPackage = $this->connection->read(); if ($binPackage === null) { - $this->logger?->info("Stream has closed the connection"); + $this->logger?->info('Stream has closed the connection'); return null; } $this->lastPackage = microtime(true); @@ -249,15 +249,15 @@ public function read(): ?Package\InPackage { } public function write(Package\OutPackage $package): void { - $this->logger?->debug("Sending package {package}", [ - "package" => $package, + $this->logger?->debug('Sending package {package}', [ + 'package' => $package, ]); $binPackage = $package->toBinaryPackage(); if ($package instanceof Package\Out\RateLimited) { - $this->logger?->debug("Sending rate-limited package via bucket-queue"); + $this->logger?->debug('Sending rate-limited package via bucket-queue'); $this->bucket->take(callback: fn () => $this->connection->write($binPackage->toBinary())); } else { - $this->logger?->debug("Sending non-rate-limited package instantly"); + $this->logger?->debug('Sending non-rate-limited package instantly'); $this->connection->write($binPackage->toBinary()); } if ($package instanceof Package\Out\Pong) { @@ -272,20 +272,20 @@ public function disconnect(): void { public function login(string $username, string $password, string $character): void { $this->loggedInChar = null; $this->loggedInUid = null; - $this->logger?->debug("Logging in with username {$username}", ["username" => $username]); + $this->logger?->debug("Logging in with username {$username}", ['username' => $username]); $this->publicGroups = []; $this->buddylist = []; $character = Utils::normalizeCharacter($character); $loginSeed = $this->read(); if ($loginSeed === null) { - throw new LoginException("No login seed received"); + throw new LoginException('No login seed received'); } if (!($loginSeed instanceof In\LoginSeed)) { throw new WrongPacketOrderException( - "Expected " . In\LoginSeed::class . ", got " . get_class($loginSeed) + 'Expected ' . In\LoginSeed::class . ', got ' . $loginSeed::class ); } - $this->logger?->debug("Received login seed {seed}, calculating reply", ["seed" => $loginSeed->serverSeed]); + $this->logger?->debug('Received login seed {seed}, calculating reply', ['seed' => $loginSeed->serverSeed]); $key = Encryption\TEA::generateLoginKey( serverKey: $loginSeed->serverSeed, username: $username, @@ -297,22 +297,22 @@ public function login(string $username, string $password, string $character): vo )); $response = $this->read(); if ($response === null) { - throw new LoginException("Connection unexpectedly closed"); + throw new LoginException('Connection unexpectedly closed'); } if ($response instanceof In\LoginError) { - $errorMsgs = explode("|", $response->error); - if (count($errorMsgs) === 3 && $errorMsgs[2] === "/Account system denies login") { + $errorMsgs = explode('|', $response->error); + if (count($errorMsgs) === 3 && $errorMsgs[2] === '/Account system denies login') { if (isset($this->accountUnfreezer) && $this->accountUnfreezer->unfreeze()) { - $this->logger?->notice("Account {account} successfully unfrozen, waiting {delay}s", [ - "account" => $username, - "delay" => 5, + $this->logger?->notice('Account {account} successfully unfrozen, waiting {delay}s', [ + 'account' => $username, + 'delay' => 5, ]); $this->accountUnfreezer = null; delay(5); $this->login(...func_get_args()); return; } - $parts = explode(": ", $errorMsgs[0] ?? ""); + $parts = explode(': ', $errorMsgs[0] ?? ''); throw new AccountFrozenException( account: new FrozenAccount( username: $username, @@ -320,24 +320,24 @@ public function login(string $username, string $password, string $character): vo ), ); } - $this->logger?->error("Error from login server: {error}", [ - "error" => $response->error, + $this->logger?->error('Error from login server: {error}', [ + 'error' => $response->error, ]); throw new LoginException($response->error); } if (!($response instanceof In\LoginCharlist)) { throw new WrongPacketOrderException( - "Expected " . In\LoginCharlist::class . ", got " . get_class($response) + 'Expected ' . In\LoginCharlist::class . ', got ' . $response::class ); } $uid = $this->getUidFromCharlist($response, $character); if ($uid === null) { $this->logger?->error( - "The character {charName} is not on the account {account}. Found only {validNames}", + 'The character {charName} is not on the account {account}. Found only {validNames}', [ - "account" => $username, - "validNames" => join(", ", $response->characters), - "charName" => $character, + 'account' => $username, + 'validNames' => implode(', ', $response->characters), + 'charName' => $character, ] ); throw new CharacterNotFoundException( @@ -347,11 +347,11 @@ public function login(string $username, string $password, string $character): vo $this->write(new Out\LoginSelectCharacter(charId: $uid)); $response = $this->read(); if ($response === null) { - throw new LoginException("Connection unexpectedly closed"); + throw new LoginException('Connection unexpectedly closed'); } if (!($response instanceof In\LoginOk)) { throw new WrongPacketOrderException( - "Expected " . In\LoginOk::class . ", got " . get_class($response) + 'Expected ' . In\LoginOk::class . ', got ' . $response::class ); } $this->loggedInChar = $character; @@ -380,39 +380,39 @@ protected function handleIncomingPackage(Package\InPackage $package): void { } protected function handleCharacterLookupResult(In\CharacterLookupResult $package): void { - $this->logger?->debug("In\\ClientLookup received, caching uid <=> name lookups"); + $this->logger?->debug('In\\ClientLookup received, caching uid <=> name lookups'); $this->nameToUid[$package->name] = $package->charId; $this->uidToName[$package->charId] = $package->name; $suspended = $this->pendingUidLookups[$package->name] ?? []; unset($this->pendingUidLookups[$package->name]); - $this->logger?->debug("{num_waiting} clients waiting for lookup result", [ - "num_waiting" => count($suspended), + $this->logger?->debug('{num_waiting} clients waiting for lookup result', [ + 'num_waiting' => count($suspended), ]); $numFiber = 1; foreach ($suspended as $thread) { - $this->logger?->debug("Resuming fiber #{fiber}", ["fiber" => $numFiber++]); + $this->logger?->debug('Resuming fiber #{fiber}', ['fiber' => $numFiber++]); $thread->resume($package->getUid()); } } protected function handleCharacterName(In\CharacterName $package): void { - $this->logger?->debug("In\\ClientName received, caching {uid} <=> \"{name}\" lookups", [ - "uid" => $package->getUid(), - "name" => $package->name, + $this->logger?->debug('In\\ClientName received, caching {uid} <=> "{name}" lookups', [ + 'uid' => $package->getUid(), + 'name' => $package->name, ]); $this->nameToUid[$package->name] = $package->charId; $this->uidToName[$package->charId] = $package->name; } protected function handleBuddyState(In\BuddyState $package): void { - $this->logger?->debug("In\\BuddyState received, putting into buddylist with status \"{online}\"", [ - "online" => ($package->online ? "online" : "offline"), + $this->logger?->debug('In\\BuddyState received, putting into buddylist with status "{online}"', [ + 'online' => ($package->online ? 'online' : 'offline'), ]); $this->buddylist[$package->charId] = $package->online; } protected function handleBuddyRemoved(In\BuddyRemoved $package): void { - $this->logger?->debug("In\\BuddyRemoved received, removing from buddylist"); + $this->logger?->debug('In\\BuddyRemoved received, removing from buddylist'); unset($this->buddylist[$package->charId]); } @@ -425,8 +425,8 @@ protected function handleGroupJoined(In\GroupJoined $package): void { name: $package->groupName, flags: $package->flags ); - $this->logger?->debug("New group {group} announced", [ - "group" => $group, + $this->logger?->debug('New group {group} announced', [ + 'group' => $group, ]); $this->publicGroups[$package->groupName] = $group; } @@ -434,8 +434,8 @@ protected function handleGroupJoined(In\GroupJoined $package): void { protected function handleGroupLeft(In\GroupLeft $package): void { foreach ($this->publicGroups as $name => $group) { if ($package->groupId->sameAs($group->id)) { - $this->logger?->debug("Removing the group {group} from our list", [ - "group" => $name, + $this->logger?->debug('Removing the group {group} from our list', [ + 'group' => $name, ]); unset($this->publicGroups[$name]); } @@ -447,20 +447,20 @@ protected function triggerOnReady(): void { return; } $this->isReady = true; - $this->logger?->notice("{charName} is now ready", [ - "charName" => $this->loggedInChar, + $this->logger?->notice('{charName} is now ready', [ + 'charName' => $this->loggedInChar, ]); while (null !== ($callback = array_shift($this->readyListeners))) { - $this->logger?->debug("Calling {closure}", [ - "closure" => Utils::closureToString($callback), + $this->logger?->debug('Calling {closure}', [ + 'closure' => Utils::closureToString($callback), ]); try { $callback(); } catch (Throwable $e) { - $this->logger?->error("Error calling {closure}: {error}", [ - "closure" => Utils::closureToString($callback), - "error" => $e->getMessage(), - "exception" => $e, + $this->logger?->error('Error calling {closure}: {error}', [ + 'closure' => Utils::closureToString($callback), + 'error' => $e->getMessage(), + 'exception' => $e, ]); } } diff --git a/src/Client/WorkerConfig.php b/src/Client/WorkerConfig.php index cedb1da..c413405 100644 --- a/src/Client/WorkerConfig.php +++ b/src/Client/WorkerConfig.php @@ -17,21 +17,21 @@ public function __construct( } public function __toString(): string { - $classes = explode("\\", get_class($this)); + $classes = explode('\\', static::class); $class = array_pop($classes); return "<{$class}>{". "dimension={$this->dimension},". "username={$this->username},". - "password=******,". + 'password=******,'. "character={$this->character}}"; } public function getServer(): string { return match ($this->dimension) { - 4 => "chat.dt.funcom.com:7109", - 5 => "chat.d1.funcom.com:7105", - 6 => "chat.d1.funcom.com:7106", - default => throw new InvalidArgumentException("No valid server to connect with! Available dimensions are 4, 5, and 6.") + 4 => 'chat.dt.funcom.com:7109', + 5 => 'chat.d1.funcom.com:7105', + 6 => 'chat.d1.funcom.com:7106', + default => throw new InvalidArgumentException('No valid server to connect with! Available dimensions are 4, 5, and 6.') }; } } diff --git a/src/Client/WorkerFiber.php b/src/Client/WorkerFiber.php index 8e87267..3f1a3c7 100644 --- a/src/Client/WorkerFiber.php +++ b/src/Client/WorkerFiber.php @@ -14,11 +14,11 @@ public function __construct( } public function __toString(): string { - $classes = explode("\\", get_class($this)); + $classes = explode('\\', static::class); $class = array_pop($classes); return "<{$class}>{". - "config=" . (string)$this->config . ",". - "socket=,". - "client=}"; + 'config=' . (string)$this->config . ','. + 'socket=,'. + 'client=}'; } } diff --git a/src/Client/WorkerPackage.php b/src/Client/WorkerPackage.php index 204c425..b180a49 100644 --- a/src/Client/WorkerPackage.php +++ b/src/Client/WorkerPackage.php @@ -14,11 +14,11 @@ public function __construct( } public function __toString(): string { - $classes = explode("\\", get_class($this)); + $classes = explode('\\', static::class); $class = array_pop($classes); return "<{$class}>{". "worker={$this->worker},". - "package=" . (string)$this->package . ",". - "client=}"; + 'package=' . (string)$this->package . ','. + 'client=}'; } } diff --git a/src/Connection.php b/src/Connection.php index 466ef43..08e4d29 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -42,7 +42,7 @@ public function read(?Cancellation $cancellation=null): ?BinaryPackage\BinaryPac return null; } $this->statistics->bytesRead += \strlen($binPackage); - $header = unpack("ntype/nlength", $binPackage); + $header = unpack('ntype/nlength', $binPackage); $package = new BinaryPackage\BinaryPackageIn( type: PackageType::from($header['type']), length: $header['length'], @@ -50,7 +50,7 @@ public function read(?Cancellation $cancellation=null): ?BinaryPackage\BinaryPac ); $this->statistics->packagesRead[$package->type->value] ??= 0; $this->statistics->packagesRead[$package->type->value]++; - $this->logger?->debug("Received {package}", ["package" => $package]); + $this->logger?->debug('Received {package}', ['package' => $package]); return $package; } @@ -79,8 +79,8 @@ public function write(string|BinaryPackage\BinaryPackageOut $bytes): void { $type = $bytes->type->value; $bytes = $bytes->toBinary(); } else { - $unpacked = unpack("ntype", $bytes); - $type = (int)$unpacked["type"]; + $unpacked = unpack('ntype', $bytes); + $type = (int)$unpacked['type']; } $this->statistics->bytesWritten += \strlen($bytes); $this->statistics->packagesWritten[$type] ??= 0; diff --git a/src/Encryption/TEA.php b/src/Encryption/TEA.php index 9424194..f9bfbb6 100644 --- a/src/Encryption/TEA.php +++ b/src/Encryption/TEA.php @@ -18,39 +18,39 @@ class TEA { * @see http://en.wikipedia.org/wiki/Diffie-Hellman_key_exchange */ public static function generateLoginKey(string $serverKey, string $username, string $password): string { - $dhY = "0x9c32cc23d559ca90fc31be72df817d0e124769e809f936bc14360ff4b". - "ed758f260a0d596584eacbbc2b88bdd410416163e11dbf62173393fbc0c6fe". - "fb2d855f1a03dec8e9f105bbad91b3437d8eb73fe2f44159597aa4053cf788". - "d2f9d7012fb8d7c4ce3876f7d6cd5d0c31754f4cd96166708641958de54a6d". - "ef5657b9f2e92"; - $dhN = "0xeca2e8c85d863dcdc26a429a71a9815ad052f6139669dd659f98ae159". - "d313d13c6bf2838e10a69b6478b64a24bd054ba8248e8fa778703b41840824". - "9440b2c1edd28853e240d8a7e49540b76d120d3b1ad2878b1b99490eb4a2a5". - "e84caa8a91cecbdb1aa7c816e8be343246f80c637abc653b893fd91686cf8d". - "32d6cfe5f2a6f"; - $dhG = "0x5"; - $dhx = "0x".self::getRandomHexKey(256); + $dhY = '0x9c32cc23d559ca90fc31be72df817d0e124769e809f936bc14360ff4b'. + 'ed758f260a0d596584eacbbc2b88bdd410416163e11dbf62173393fbc0c6fe'. + 'fb2d855f1a03dec8e9f105bbad91b3437d8eb73fe2f44159597aa4053cf788'. + 'd2f9d7012fb8d7c4ce3876f7d6cd5d0c31754f4cd96166708641958de54a6d'. + 'ef5657b9f2e92'; + $dhN = '0xeca2e8c85d863dcdc26a429a71a9815ad052f6139669dd659f98ae159'. + 'd313d13c6bf2838e10a69b6478b64a24bd054ba8248e8fa778703b41840824'. + '9440b2c1edd28853e240d8a7e49540b76d120d3b1ad2878b1b99490eb4a2a5'. + 'e84caa8a91cecbdb1aa7c816e8be343246f80c637abc653b893fd91686cf8d'. + '32d6cfe5f2a6f'; + $dhG = '0x5'; + $dhx = '0x'.self::getRandomHexKey(256); $dhX = self::bcmathPowM($dhG, $dhx, $dhN); $dhK = self::bcmathPowM($dhY, $dhx, $dhN); - $str = sprintf("%s|%s|%s", $username, $serverKey, $password); + $str = sprintf('%s|%s|%s', $username, $serverKey, $password); if (strlen($dhK) < 32) { - $dhK = str_repeat("0", 32-strlen($dhK)) . $dhK; + $dhK = str_repeat('0', 32-strlen($dhK)) . $dhK; } else { $dhK = substr($dhK, 0, 32); } - $prefix = pack("H16", self::getRandomHexKey(64)); + $prefix = pack('H16', self::getRandomHexKey(64)); $length = 8 + 4 + strlen($str); // prefix, int, ... - $pad = str_repeat(" ", (8 - $length % 8) % 8); - $strlen = pack("N", strlen($str)); + $pad = str_repeat(' ', (8 - $length % 8) % 8); + $strlen = pack('N', strlen($str)); $plain = $prefix . $strlen . $str . $pad; $encrypted = self::aoChatCrypt($dhK, $plain); - return $dhX . "-" . $encrypted; + return $dhX . '-' . $encrypted; } /** @@ -60,9 +60,9 @@ public static function generateLoginKey(string $serverKey, string $username, str * This can be used instead of unpack/pack to get the value we need. */ private static function safeDecHexReverseEndian(float $value): string { - $result = ""; + $result = ''; $value = self::reduceTo32Bit($value); - $hex = substr("00000000".dechex($value), -8); + $hex = substr('00000000'.dechex($value), -8); $bytes = str_split($hex, 2); @@ -76,13 +76,13 @@ private static function safeDecHexReverseEndian(float $value): string { /** Do an AOChat-conform encryption of $str with $key */ private static function aoChatCrypt(string $key, string $str): string { if (strlen($key) !== 32 || strlen($str) % 8 !== 0) { - throw new InvalidArgumentException("Invalid key or string received."); + throw new InvalidArgumentException('Invalid key or string received.'); } - $ret = ""; + $ret = ''; - $keyarr = unpack("V*", pack("H*", $key)); - $dataarr = unpack("V*", $str); + $keyarr = unpack('V*', pack('H*', $key)); + $dataarr = unpack('V*', $str); $prev = [0, 0]; for ($i = 1; $i <= count($dataarr); $i += 2) { @@ -101,7 +101,7 @@ private static function aoChatCrypt(string $key, string $str): string { /** Generate a random hex string with $bits bits length */ private static function getRandomHexKey(int $bits): string { - $str = ""; + $str = ''; do { $str .= sprintf('%02x', random_int(0, 0xFF)); } while (($bits -= 8) > 0); @@ -110,7 +110,7 @@ private static function getRandomHexKey(int $bits): string { /** Raise an arbitrary precision number to another, reduced by a specified modulus */ private static function bcmathPowM(string $base, string $exp, string $mod): string { - if (function_exists("gmp_powm") && function_exists("gmp_strval")) { + if (function_exists('gmp_powm') && function_exists('gmp_strval')) { $r = gmp_powm($base, $exp, $mod); $r = gmp_strval($r); } else { @@ -124,19 +124,19 @@ private static function bcmathPowM(string $base, string $exp, string $mod): stri $r = bcpowmod($base, $exp, $mod); } if (!is_string($r)) { - throw new Exception("Error in AO encryption"); + throw new Exception('Error in AO encryption'); } return self::bigDecHex($r); } /** Convert a HEX value into a decimal value */ private static function bigHexCec(string $x): string { - if (substr($x, 0, 2) !== "0x") { + if (substr($x, 0, 2) !== '0x') { return $x; } - $r = "0"; + $r = '0'; for ($p = $q = strlen($x) - 1; $p >= 2; $p--) { - $r = bcadd($r, bcmul((string)hexdec($x[$p]), bcpow("16", (string)($q - $p)))); + $r = bcadd($r, bcmul((string)hexdec($x[$p]), bcpow('16', (string)($q - $p)))); } return $r; } @@ -146,10 +146,10 @@ private static function bigDecHex(string $x): string { if (!is_numeric($x)) { throw new InvalidArgumentException("Invalid numeric string encountered: {$x}"); } - $r = ""; - while ($x !== "0") { - $r = dechex((int)bcmod($x, "16")) . $r; - $x = bcdiv($x, "16"); + $r = ''; + while ($x !== '0') { + $r = dechex((int)bcmod($x, '16')) . $r; + $x = bcdiv($x, '16'); } return $r; } @@ -166,20 +166,20 @@ private static function bigDecHex(string $x): string { private static function reduceTo32Bit(float $value): int { $strValue = (string)$value; // If its negative, lets go positive ... its easier to do everything as positive. - if (bccomp($strValue, "0") === -1) { + if (bccomp($strValue, '0') === -1) { $strValue = self::negativeToUnsigned($value); } if (!is_numeric($strValue)) { throw new Exception("Invalid numeric string encountered: {$strValue}"); } - $bit32 = (string)0x80000000; + $bit32 = (string)0x80_00_00_00; $bit = $bit32; $bits = []; // Find the largest bit contained in $value above 32-bits while (bccomp($strValue, $bit) > -1) { - $bit = bcmul($bit, "2"); + $bit = bcmul($bit, '2'); $bits[] = $bit; } @@ -211,22 +211,22 @@ private static function reduceTo32Bit(float $value): int { */ private static function negativeToUnsigned(float $value): string { $strValue = (string)$value; - if (bccomp($strValue, "0") !== -1) { + if (bccomp($strValue, '0') !== -1) { return $strValue; } - $strValue = bcmul($strValue, "-1"); - $higherValue = (string)0xFFFFFFFF; + $strValue = bcmul($strValue, '-1'); + $higherValue = (string)0xFF_FF_FF_FF; // We don't know how many bytes the integer might be, so // start with one byte and then grow it byte by byte until // our negative number fits inside it. This will make the resulting // positive number fit in the same number of bytes. while (bccomp($strValue, $higherValue) === 1) { - $higherValue = bcadd(bcmul($higherValue, (string)0x100), (string)0xFF); + $higherValue = bcadd(bcmul($higherValue, (string)0x1_00), (string)0xFF); } - $strValue = bcadd(bcsub($higherValue, $strValue), "1"); + $strValue = bcadd(bcsub($higherValue, $strValue), '1'); return $strValue; } @@ -245,7 +245,7 @@ private static function aoCryptPermute(array $x, array $y): array { $a = $x[0]; $b = $x[1]; $c = 0; - $d = 0x9E3779B9; + $d = 0x9E_37_79_B9; for ($i = 32; $i-- > 0;) { $c = self::reduceTo32Bit($c + $d); $a += self::reduceTo32Bit( @@ -253,14 +253,14 @@ private static function aoCryptPermute(array $x, array $y): array { (self::reduceTo32Bit($b) << 4 & -16) + $y[1] ) ^ self::reduceTo32Bit($b + $c) ) ^ self::reduceTo32Bit( - (self::reduceTo32Bit($b) >> 5 & 134217727) + $y[2] + (self::reduceTo32Bit($b) >> 5 & 134_217_727) + $y[2] ); $b += self::reduceTo32Bit( self::reduceTo32Bit( (self::reduceTo32Bit($a) << 4 & -16) + $y[3] ) ^ self::reduceTo32Bit($a + $c) ) ^ self::reduceTo32Bit( - (self::reduceTo32Bit($a) >> 5 & 134217727) + $y[4] + (self::reduceTo32Bit($a) >> 5 & 134_217_727) + $y[4] ); } return [$a, $b]; diff --git a/src/Exceptions/AccountFrozenException.php b/src/Exceptions/AccountFrozenException.php index 73895e0..62fa343 100644 --- a/src/Exceptions/AccountFrozenException.php +++ b/src/Exceptions/AccountFrozenException.php @@ -8,7 +8,7 @@ class AccountFrozenException extends LoginException { public function __construct( private readonly FrozenAccount $account, ) { - parent::__construct(message: "Your account is currently frozen"); + parent::__construct(message: 'Your account is currently frozen'); } public function getAccount(): FrozenAccount { diff --git a/src/Exceptions/AccountsFrozenException.php b/src/Exceptions/AccountsFrozenException.php index f09325d..29b8eff 100644 --- a/src/Exceptions/AccountsFrozenException.php +++ b/src/Exceptions/AccountsFrozenException.php @@ -9,7 +9,7 @@ class AccountsFrozenException extends LoginException { public function __construct( private readonly array $accounts, ) { - parent::__construct(message: "One or more accounts are currently frozen"); + parent::__construct(message: 'One or more accounts are currently frozen'); } /** @return FrozenAccount[] */ diff --git a/src/Group.php b/src/Group.php index 1f501d8..7e00c56 100644 --- a/src/Group.php +++ b/src/Group.php @@ -3,10 +3,10 @@ namespace AO; class Group { - public const NO_WRITE = 0x00000002; - public const NO_ASIAN = 0x00000020; - public const MUTE = 0x01010000; - public const LOG = 0x02020000; + public const NO_WRITE = 0x00_00_00_02; + public const NO_ASIAN = 0x00_00_00_20; + public const MUTE = 0x01_01_00_00; + public const LOG = 0x02_02_00_00; final public function __construct( public readonly Group\GroupId $id, diff --git a/src/Group/GroupId.php b/src/Group/GroupId.php index a8eb981..68860e8 100644 --- a/src/Group/GroupId.php +++ b/src/Group/GroupId.php @@ -21,7 +21,7 @@ public function __toString(): string { } public function toBinary(): string { - return pack("CN", $this->type->value, $this->number); + return pack('CN', $this->type->value, $this->number); } public function sameAs(self $other): bool { diff --git a/src/Internal/BinaryString.php b/src/Internal/BinaryString.php index f8b34e0..615ef6f 100644 --- a/src/Internal/BinaryString.php +++ b/src/Internal/BinaryString.php @@ -9,8 +9,8 @@ public function __construct(private string $data) { } public function __toString(): string { - $binData = join( - "", + $binData = implode( + '', array_map( dechex(...), array_map( diff --git a/src/Internal/MaybeBinaryString.php b/src/Internal/MaybeBinaryString.php index e73ea25..dd6a553 100644 --- a/src/Internal/MaybeBinaryString.php +++ b/src/Internal/MaybeBinaryString.php @@ -14,20 +14,20 @@ public function __toString(): string { $ord = ord($this->data[$i]); switch ($ord) { case 9: // - $bin .= "\\t"; + $bin .= '\\t'; break; case 10: // - $bin .= "\\n"; + $bin .= '\\n'; break; case 34: // " - $bin .= "\\\""; + $bin .= '\\"'; break; case 92: // \ - $bin .= "\\\\"; + $bin .= '\\\\'; break; default: if ($ord < 32 || $ord > 127) { - $bin .= "\\x" . sprintf("%02X", $ord); + $bin .= '\\x' . sprintf('%02X', $ord); } else { $bin .= $this->data[$i]; } diff --git a/src/MMDB/AsyncClient.php b/src/MMDB/AsyncMMDBClient.php similarity index 74% rename from src/MMDB/AsyncClient.php rename to src/MMDB/AsyncMMDBClient.php index 7724e07..121cc19 100644 --- a/src/MMDB/AsyncClient.php +++ b/src/MMDB/AsyncMMDBClient.php @@ -12,7 +12,7 @@ /** * Reads entries from the text.mdb file */ -class AsyncClient implements Client { +class AsyncMMDBClient implements MMDBClient { /** * A cache to quickly access the most common lookups * @@ -26,20 +26,20 @@ public function __construct( ) { $this->mmdb->seek(0); $entry = $this->readEntry(); - if ($entry->id !== 1111772493) { - throw new InvalidArgumentException("Argument \$mmdb to " . __CLASS__ . " is not an mmdb file: '" . $mmdb->getPath() . "'"); + if ($entry->id !== 1_111_772_493) { + throw new InvalidArgumentException('Argument $mmdb to ' . __CLASS__ . " is not an mmdb file: '" . $mmdb->getPath() . "'"); } } public static function createDefault(): self { - $file = openFile(dirname(__DIR__, 2) . "/data/text.mdb", "rb"); + $file = openFile(dirname(__DIR__, 2) . '/data/text.mdb', 'rb'); return new self(mmdb: $file); } public function getMessageString(int $categoryId, int $messageId): ?string { - $this->logger?->info("Looking up messageId={message_id}, categoryId={category_id}", [ - "category_id"=> $categoryId, - "message_id" => $messageId, + $this->logger?->info('Looking up messageId={message_id}, categoryId={category_id}', [ + 'category_id'=> $categoryId, + 'message_id' => $messageId, ]); // check for entry in cache if (isset($this->cache[$categoryId][$messageId])) { @@ -52,8 +52,8 @@ public function getMessageString(int $categoryId, int $messageId): ?string { // find the category $category = $this->findEntry($categoryId, 8); if ($category === null) { - $this->logger?->error("Could not find categoryID {category_id}", [ - "category_id"=> $categoryId, + $this->logger?->error('Could not find categoryID {category_id}', [ + 'category_id'=> $categoryId, ]); return null; } @@ -61,9 +61,9 @@ public function getMessageString(int $categoryId, int $messageId): ?string { // find the instance $instance = $this->findEntry($messageId, $category->offset); if ($instance === null) { - $this->logger?->error("Could not find messageId {message_id} for categoryId {category_id}", [ - "category_id"=> $categoryId, - "message_id" => $messageId, + $this->logger?->error('Could not find messageId {message_id} for categoryId {category_id}', [ + 'category_id'=> $categoryId, + 'message_id' => $messageId, ]); return null; } @@ -75,14 +75,14 @@ public function getMessageString(int $categoryId, int $messageId): ?string { return $message; } - /** @return Entry[]|null */ + /** @return MMDBEntry[]|null */ public function findAllInstancesInCategory(int $categoryId): ?array { // start at offset = 8 since that is where the categories start // find the category $category = $this->findEntry($categoryId, 8); if ($category === null) { - $this->logger?->error("Could not find categoryID {category_id}", [ - "category_id" => $categoryId, + $this->logger?->error('Could not find categoryID {category_id}', [ + 'category_id' => $categoryId, ]); return null; } @@ -102,7 +102,7 @@ public function findAllInstancesInCategory(int $categoryId): ?array { return $instances; } - /** @return null|Entry[] */ + /** @return null|MMDBEntry[] */ public function getCategories(): ?array { // start at offset = 8 since that is where the categories start $this->mmdb->seek(8); @@ -126,7 +126,7 @@ public function getCategories(): ?array { * @param int $id The category ID * @param int $offset Offset where to read */ - private function findEntry(int $id, int $offset): ?Entry { + private function findEntry(int $id, int $offset): ?MMDBEntry { $this->mmdb->seek($offset); $entry = null; @@ -142,8 +142,8 @@ private function findEntry(int $id, int $offset): ?Entry { return $entry; } - private function readEntry(): Entry { - return new Entry( + private function readEntry(): MMDBEntry { + return new MMDBEntry( id: $this->readLong(), offset: $this->readLong(), ); @@ -152,9 +152,9 @@ private function readEntry(): Entry { private function readLong(): int { $packed = $this->mmdb->read(length: 4); if ($packed === null || strlen($packed) < 4) { - throw new \Exception("The MMDB file is broken"); + throw new \Exception('The MMDB file is broken'); } - $unpacked = unpack("L", $packed); + $unpacked = unpack('L', $packed); return array_pop($unpacked); } @@ -164,13 +164,13 @@ private function readString(): string { $char = $this->mmdb->read(length: 1); if ($char === null || strlen($char) < 1) { - throw new \Exception("The MMDB file is broken"); + throw new \Exception('The MMDB file is broken'); } while ($char !== "\0" && !$this->mmdb->eof()) { $message .= $char; $char = $this->mmdb->read(length: 1); if ($char === null) { - throw new \Exception("The MMDB file is broken"); + throw new \Exception('The MMDB file is broken'); } } diff --git a/src/MMDB/Client.php b/src/MMDB/MMDBClient.php similarity index 90% rename from src/MMDB/Client.php rename to src/MMDB/MMDBClient.php index 300a62a..120d6d0 100644 --- a/src/MMDB/Client.php +++ b/src/MMDB/MMDBClient.php @@ -5,6 +5,6 @@ /** * A generic interface for an MMDB client that allows reading predefined strings */ -interface Client { +interface MMDBClient { public function getMessageString(int $categoryId, int $messageId): ?string; } diff --git a/src/MMDB/Entry.php b/src/MMDB/MMDBEntry.php similarity index 84% rename from src/MMDB/Entry.php rename to src/MMDB/MMDBEntry.php index d06675e..d7ec7c3 100644 --- a/src/MMDB/Entry.php +++ b/src/MMDB/MMDBEntry.php @@ -2,7 +2,7 @@ namespace AO\MMDB; -final class Entry { +final class MMDBEntry { public function __construct( public int $id, public int $offset, diff --git a/src/Package.php b/src/Package.php index 1206b48..47d7b3e 100644 --- a/src/Package.php +++ b/src/Package.php @@ -30,12 +30,12 @@ public function __toString() { } elseif ($value instanceof \UnitEnum) { $value = $value->name; } elseif ($value instanceof \Closure) { - $value = ""; + $value = ''; } else { try { $value = json_encode( $value, - JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE|JSON_INVALID_UTF8_SUBSTITUTE + \JSON_UNESCAPED_SLASHES|\JSON_UNESCAPED_UNICODE|\JSON_INVALID_UTF8_SUBSTITUTE ); } catch (JsonException) { continue; @@ -43,19 +43,19 @@ public function __toString() { } $values []= "{$key}={$value}"; } - $classes = explode("\\", get_class($this)); + $classes = explode('\\', static::class); $class = array_pop($classes); - return "<{$class}>{" . join(",", $values) . "}"; + return "<{$class}>{" . implode(',', $values) . '}'; } public function toBinaryPackage(): BinaryPackage { $type = $this->type; $format = $this->getFormat(); $values = $this->getPackageValues(); - $body = ""; + $body = ''; for ($i = 0; $i < strlen($format); $i++) { if (!isset($values[$i])) { - throw new \Exception("The declaration of " . self::class . "and its binary representation is inconsistent."); + throw new \Exception('The declaration of ' . self::class . 'and its binary representation is inconsistent.'); } $body .= $this->toFormat(substr($format, $i, 1), $values[$i]); } @@ -72,7 +72,7 @@ abstract public static function getFormat(): string; protected function getPackageValues(): array { $result = []; $refClass = new \ReflectionClass($this); - $refFunc = $refClass->getMethod("__construct"); + $refFunc = $refClass->getMethod('__construct'); $refParams = $refFunc->getParameters(); $pos = 0; foreach ($refParams as $refParam) { @@ -97,30 +97,30 @@ protected function getPackageValues(): array { /** @param bool|int|string|string[]|int[]|GroupId $value */ protected function toFormat(string $format, bool|int|string|array|GroupId $value): string { switch ($format) { - case "B": + case 'B': assert(is_bool($value)); - return pack("N", (int)$value); - case "I": + return pack('N', (int)$value); + case 'I': assert(is_int($value)); - return pack("N", $value); - case "S": + return pack('N', $value); + case 'S': assert(is_string($value)); - return pack("n", strlen($value)) . $value; - case "G": + return pack('n', strlen($value)) . $value; + case 'G': assert(is_object($value)); assert($value instanceof GroupId); - return pack("CN", $value->type->value, $value->number); - case "i": + return pack('CN', $value->type->value, $value->number); + case 'i': assert(is_array($value)); $count = count($value); return pack("nN{$count}", $count, ...$value); - case "s": + case 's': assert(is_array($value)); $count = count($value); - $result = pack("n", $count); + $result = pack('n', $count); foreach ($value as $element) { assert(is_string($element)); - $result .= pack("n", strlen($element)) . $element; + $result .= pack('n', strlen($element)) . $element; } return $result; default: diff --git a/src/Package/In/AdmMuxInfo.php b/src/Package/In/AdmMuxInfo.php index 22aa4dc..100445c 100644 --- a/src/Package/In/AdmMuxInfo.php +++ b/src/Package/In/AdmMuxInfo.php @@ -19,6 +19,6 @@ public function __construct( } public static function getFormat(): string { - return "iii"; + return 'iii'; } } diff --git a/src/Package/In/BroadcastMessage.php b/src/Package/In/BroadcastMessage.php index 22bb33e..10d0408 100644 --- a/src/Package/In/BroadcastMessage.php +++ b/src/Package/In/BroadcastMessage.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "SSS"; + return 'SSS'; } } diff --git a/src/Package/In/BuddyRemoved.php b/src/Package/In/BuddyRemoved.php index 3c3ca4a..4527ddf 100644 --- a/src/Package/In/BuddyRemoved.php +++ b/src/Package/In/BuddyRemoved.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/In/BuddyState.php b/src/Package/In/BuddyState.php index c0d2d77..b69279e 100644 --- a/src/Package/In/BuddyState.php +++ b/src/Package/In/BuddyState.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "IBS"; + return 'IBS'; } } diff --git a/src/Package/In/CharacterLookupResult.php b/src/Package/In/CharacterLookupResult.php index a46b08b..b23056d 100644 --- a/src/Package/In/CharacterLookupResult.php +++ b/src/Package/In/CharacterLookupResult.php @@ -13,10 +13,10 @@ public function __construct( } public function getUid(): ?int { - return $this->charId === 0xFFFFFFFF ? null : $this->charId; + return $this->charId === 0xFF_FF_FF_FF ? null : $this->charId; } public static function getFormat(): string { - return "IS"; + return 'IS'; } } diff --git a/src/Package/In/CharacterName.php b/src/Package/In/CharacterName.php index f5637fa..5d1b01f 100644 --- a/src/Package/In/CharacterName.php +++ b/src/Package/In/CharacterName.php @@ -13,10 +13,10 @@ public function __construct( } public function getUid(): ?int { - return $this->charId === 0xFFFFFFFF ? null : $this->charId; + return $this->charId === 0xFF_FF_FF_FF ? null : $this->charId; } public static function getFormat(): string { - return "IS"; + return 'IS'; } } diff --git a/src/Package/In/CharacterUnknown.php b/src/Package/In/CharacterUnknown.php index db92546..2fe66da 100644 --- a/src/Package/In/CharacterUnknown.php +++ b/src/Package/In/CharacterUnknown.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/In/GroupJoined.php b/src/Package/In/GroupJoined.php index 4e86233..4bbdfa8 100644 --- a/src/Package/In/GroupJoined.php +++ b/src/Package/In/GroupJoined.php @@ -15,6 +15,6 @@ public function __construct( } public static function getFormat(): string { - return "GSIS"; + return 'GSIS'; } } diff --git a/src/Package/In/GroupLeft.php b/src/Package/In/GroupLeft.php index a3ee345..1880907 100644 --- a/src/Package/In/GroupLeft.php +++ b/src/Package/In/GroupLeft.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "G"; + return 'G'; } } diff --git a/src/Package/In/GroupMessage.php b/src/Package/In/GroupMessage.php index f01f1cb..48c7384 100644 --- a/src/Package/In/GroupMessage.php +++ b/src/Package/In/GroupMessage.php @@ -16,6 +16,6 @@ public function __construct( } public static function getFormat(): string { - return "GISS"; + return 'GISS'; } } diff --git a/src/Package/In/LoginCharlist.php b/src/Package/In/LoginCharlist.php index d0f08ce..fa86595 100644 --- a/src/Package/In/LoginCharlist.php +++ b/src/Package/In/LoginCharlist.php @@ -21,6 +21,6 @@ public function __construct( } public static function getFormat(): string { - return "isib"; + return 'isib'; } } diff --git a/src/Package/In/LoginError.php b/src/Package/In/LoginError.php index 0a2b1bc..386ff37 100644 --- a/src/Package/In/LoginError.php +++ b/src/Package/In/LoginError.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "S"; + return 'S'; } } diff --git a/src/Package/In/LoginOk.php b/src/Package/In/LoginOk.php index 7992e63..4c4d84e 100644 --- a/src/Package/In/LoginOk.php +++ b/src/Package/In/LoginOk.php @@ -10,6 +10,6 @@ public function __construct() { } public static function getFormat(): string { - return ""; + return ''; } } diff --git a/src/Package/In/LoginSeed.php b/src/Package/In/LoginSeed.php index cfd5090..9927973 100644 --- a/src/Package/In/LoginSeed.php +++ b/src/Package/In/LoginSeed.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "S"; + return 'S'; } } diff --git a/src/Package/In/Ping.php b/src/Package/In/Ping.php index 682da22..7743b45 100644 --- a/src/Package/In/Ping.php +++ b/src/Package/In/Ping.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "S"; + return 'S'; } } diff --git a/src/Package/In/PrivateChannelClientJoined.php b/src/Package/In/PrivateChannelClientJoined.php index d902228..423b548 100644 --- a/src/Package/In/PrivateChannelClientJoined.php +++ b/src/Package/In/PrivateChannelClientJoined.php @@ -13,6 +13,6 @@ public function __construct( } public static function getFormat(): string { - return "II"; + return 'II'; } } diff --git a/src/Package/In/PrivateChannelClientLeft.php b/src/Package/In/PrivateChannelClientLeft.php index 8f0db37..9782c9e 100644 --- a/src/Package/In/PrivateChannelClientLeft.php +++ b/src/Package/In/PrivateChannelClientLeft.php @@ -13,6 +13,6 @@ public function __construct( } public static function getFormat(): string { - return "II"; + return 'II'; } } diff --git a/src/Package/In/PrivateChannelInviteRefused.php b/src/Package/In/PrivateChannelInviteRefused.php index e5ca4e3..ebc2d29 100644 --- a/src/Package/In/PrivateChannelInviteRefused.php +++ b/src/Package/In/PrivateChannelInviteRefused.php @@ -13,6 +13,6 @@ public function __construct( } public static function getFormat(): string { - return "II"; + return 'II'; } } diff --git a/src/Package/In/PrivateChannelInvited.php b/src/Package/In/PrivateChannelInvited.php index 6c7a55a..0ce135a 100644 --- a/src/Package/In/PrivateChannelInvited.php +++ b/src/Package/In/PrivateChannelInvited.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/In/PrivateChannelKicked.php b/src/Package/In/PrivateChannelKicked.php index bbac40a..57beb7f 100644 --- a/src/Package/In/PrivateChannelKicked.php +++ b/src/Package/In/PrivateChannelKicked.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/In/PrivateChannelLeft.php b/src/Package/In/PrivateChannelLeft.php index d9e78d4..7f5dba3 100644 --- a/src/Package/In/PrivateChannelLeft.php +++ b/src/Package/In/PrivateChannelLeft.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/In/PrivateChannelMessage.php b/src/Package/In/PrivateChannelMessage.php index c1115b2..8869125 100644 --- a/src/Package/In/PrivateChannelMessage.php +++ b/src/Package/In/PrivateChannelMessage.php @@ -15,6 +15,6 @@ public function __construct( } public static function getFormat(): string { - return "IISS"; + return 'IISS'; } } diff --git a/src/Package/In/SimpleSystemMessage.php b/src/Package/In/SimpleSystemMessage.php index b1d3b41..2993215 100644 --- a/src/Package/In/SimpleSystemMessage.php +++ b/src/Package/In/SimpleSystemMessage.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "S"; + return 'S'; } } diff --git a/src/Package/In/SystemMessage.php b/src/Package/In/SystemMessage.php index 4c23890..bb0df0c 100644 --- a/src/Package/In/SystemMessage.php +++ b/src/Package/In/SystemMessage.php @@ -15,6 +15,6 @@ public function __construct( } public static function getFormat(): string { - return "IIIS"; + return 'IIIS'; } } diff --git a/src/Package/In/Tell.php b/src/Package/In/Tell.php index 6041a16..e3a68ad 100644 --- a/src/Package/In/Tell.php +++ b/src/Package/In/Tell.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "ISS"; + return 'ISS'; } } diff --git a/src/Package/In/VicinityMessage.php b/src/Package/In/VicinityMessage.php index 2f9b3c4..954c7cf 100644 --- a/src/Package/In/VicinityMessage.php +++ b/src/Package/In/VicinityMessage.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "ISS"; + return 'ISS'; } } diff --git a/src/Package/Out/BuddyAdd.php b/src/Package/Out/BuddyAdd.php index e9b0b63..2a18fac 100644 --- a/src/Package/Out/BuddyAdd.php +++ b/src/Package/Out/BuddyAdd.php @@ -13,6 +13,6 @@ public function __construct( } public static function getFormat(): string { - return "IS"; + return 'IS'; } } diff --git a/src/Package/Out/BuddyRemove.php b/src/Package/Out/BuddyRemove.php index f1208c1..1f79a35 100644 --- a/src/Package/Out/BuddyRemove.php +++ b/src/Package/Out/BuddyRemove.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/Out/CharacterLookup.php b/src/Package/Out/CharacterLookup.php index fd28182..060d285 100644 --- a/src/Package/Out/CharacterLookup.php +++ b/src/Package/Out/CharacterLookup.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "S"; + return 'S'; } } diff --git a/src/Package/Out/ChatCommand.php b/src/Package/Out/ChatCommand.php index 29686d5..acdeac8 100644 --- a/src/Package/Out/ChatCommand.php +++ b/src/Package/Out/ChatCommand.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "sI"; + return 'sI'; } } diff --git a/src/Package/Out/ClientmodeGet.php b/src/Package/Out/ClientmodeGet.php index 3f3e3bd..377fe68 100644 --- a/src/Package/Out/ClientmodeGet.php +++ b/src/Package/Out/ClientmodeGet.php @@ -13,6 +13,6 @@ public function __construct( } public static function getFormat(): string { - return "IG"; + return 'IG'; } } diff --git a/src/Package/Out/ClientmodeSet.php b/src/Package/Out/ClientmodeSet.php index 2ebadee..807eb45 100644 --- a/src/Package/Out/ClientmodeSet.php +++ b/src/Package/Out/ClientmodeSet.php @@ -15,6 +15,6 @@ public function __construct( } public static function getFormat(): string { - return "IIII"; + return 'IIII'; } } diff --git a/src/Package/Out/GroupDataSet.php b/src/Package/Out/GroupDataSet.php index 40fe7d5..1f7077d 100644 --- a/src/Package/Out/GroupDataSet.php +++ b/src/Package/Out/GroupDataSet.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "GIS"; + return 'GIS'; } } diff --git a/src/Package/Out/GroupMessage.php b/src/Package/Out/GroupMessage.php index 5166919..d245f50 100644 --- a/src/Package/Out/GroupMessage.php +++ b/src/Package/Out/GroupMessage.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "GSS"; + return 'GSS'; } } diff --git a/src/Package/Out/GroupSetClientMode.php b/src/Package/Out/GroupSetClientMode.php index 2d5d4bc..9667d54 100644 --- a/src/Package/Out/GroupSetClientMode.php +++ b/src/Package/Out/GroupSetClientMode.php @@ -16,6 +16,6 @@ public function __construct( } public static function getFormat(): string { - return "GIIII"; + return 'GIIII'; } } diff --git a/src/Package/Out/LoginRequest.php b/src/Package/Out/LoginRequest.php index d94cc66..e384caf 100644 --- a/src/Package/Out/LoginRequest.php +++ b/src/Package/Out/LoginRequest.php @@ -7,17 +7,14 @@ class LoginRequest extends Package\OutPackage { public function __construct( - #[Attr\Param(1)] - public string $username, - #[Attr\Param(2)] - public string $key, - #[Attr\Param(0)] - public int $zero=0, + #[Attr\Param(1)] public string $username, + #[Attr\Param(2)] public string $key, + #[Attr\Param(0)] public int $zero=0, ) { parent::__construct(Package\PackageType::LoginRequest); } public static function getFormat(): string { - return "ISS"; + return 'ISS'; } } diff --git a/src/Package/Out/LoginSelectCharacter.php b/src/Package/Out/LoginSelectCharacter.php index cc62893..51ace92 100644 --- a/src/Package/Out/LoginSelectCharacter.php +++ b/src/Package/Out/LoginSelectCharacter.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/Out/Pong.php b/src/Package/Out/Pong.php index 553e16e..f8f4e69 100644 --- a/src/Package/Out/Pong.php +++ b/src/Package/Out/Pong.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "S"; + return 'S'; } } diff --git a/src/Package/Out/PrivateChannelInvite.php b/src/Package/Out/PrivateChannelInvite.php index 019aaf3..a2d425f 100644 --- a/src/Package/Out/PrivateChannelInvite.php +++ b/src/Package/Out/PrivateChannelInvite.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/Out/PrivateChannelJoin.php b/src/Package/Out/PrivateChannelJoin.php index f4aba72..5f77eaf 100644 --- a/src/Package/Out/PrivateChannelJoin.php +++ b/src/Package/Out/PrivateChannelJoin.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/Out/PrivateChannelKick.php b/src/Package/Out/PrivateChannelKick.php index d2f53de..ee84c82 100644 --- a/src/Package/Out/PrivateChannelKick.php +++ b/src/Package/Out/PrivateChannelKick.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/Out/PrivateChannelKickAll.php b/src/Package/Out/PrivateChannelKickAll.php index 5b52968..e854f50 100644 --- a/src/Package/Out/PrivateChannelKickAll.php +++ b/src/Package/Out/PrivateChannelKickAll.php @@ -10,6 +10,6 @@ public function __construct() { } public static function getFormat(): string { - return ""; + return ''; } } diff --git a/src/Package/Out/PrivateChannelLeave.php b/src/Package/Out/PrivateChannelLeave.php index 8fefc58..c1203d0 100644 --- a/src/Package/Out/PrivateChannelLeave.php +++ b/src/Package/Out/PrivateChannelLeave.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "I"; + return 'I'; } } diff --git a/src/Package/Out/PrivateChannelMessage.php b/src/Package/Out/PrivateChannelMessage.php index 96770df..66030d2 100644 --- a/src/Package/Out/PrivateChannelMessage.php +++ b/src/Package/Out/PrivateChannelMessage.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "ISS"; + return 'ISS'; } } diff --git a/src/Package/Out/SetOnlineStatus.php b/src/Package/Out/SetOnlineStatus.php index e52d90d..a0bd20a 100644 --- a/src/Package/Out/SetOnlineStatus.php +++ b/src/Package/Out/SetOnlineStatus.php @@ -12,6 +12,6 @@ public function __construct( } public static function getFormat(): string { - return "B"; + return 'B'; } } diff --git a/src/Package/Out/Tell.php b/src/Package/Out/Tell.php index e769818..b007885 100644 --- a/src/Package/Out/Tell.php +++ b/src/Package/Out/Tell.php @@ -14,6 +14,6 @@ public function __construct( } public static function getFormat(): string { - return "ISS"; + return 'ISS'; } } diff --git a/src/Package/PackageType.php b/src/Package/PackageType.php index cee8ad5..3f8f823 100644 --- a/src/Package/PackageType.php +++ b/src/Package/PackageType.php @@ -32,7 +32,7 @@ public function classIn(): string { static::PublicChannelMessage => In\GroupMessage::class, static::Ping => In\Ping::class, static::AdmMuxInfo => In\AdmMuxInfo::class, - default => throw new \InvalidArgumentException($this->name . " needs a class representation."), + default => throw new \InvalidArgumentException($this->name . ' needs a class representation.'), }; } @@ -60,7 +60,7 @@ public function classOut(): string { static::Ping => Out\Pong::class, static::ChatCommand => Out\ChatCommand::class, - default => throw new \InvalidArgumentException($this->name . " needs a class representation."), + default => throw new \InvalidArgumentException($this->name . ' needs a class representation.'), }; } @@ -99,5 +99,5 @@ public function classOut(): string { case ClientModeSet = 71; case Ping = 100; case ChatCommand = 120; - case AdmMuxInfo = 1100; + case AdmMuxInfo = 1_100; } diff --git a/src/Parser.php b/src/Parser.php index b61d621..dad4926 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -12,14 +12,14 @@ class Parser { final public function __construct( - protected MMDB\Client $mmdb, + protected MMDB\MMDBClient $mmdb, protected ?LoggerInterface $logger=null, ) { } public static function createDefault(): static { return new static( - mmdb: MMDB\AsyncClient::createDefault() + mmdb: MMDB\AsyncMMDBClient::createDefault() ); } @@ -47,9 +47,9 @@ public function parseBinaryPackage(BinaryPackage $package): Package { assert(is_int($args[1])); assert(is_string($args[2])); /* Hack to support extended messages */ - if ($args[1] === 0 && substr($args[2], 0, 2) == "~&") { - $this->logger?->debug("Extended message {message} found", [ - "message" => $args[2], + if ($args[1] === 0 && substr($args[2], 0, 2) == '~&') { + $this->logger?->debug('Extended message {message} found', [ + 'message' => $args[2], ]); $extMsg = $this->readExtendedMessage($args[2]); if (isset($extMsg)) { @@ -62,15 +62,15 @@ public function parseBinaryPackage(BinaryPackage $package): Package { assert(count($args) == 4); assert(is_int($args[2])); assert(is_string($args[3])); - $categoryId = 20000; + $categoryId = 20_000; $extMsg = $this->mmdb->getMessageString($categoryId, $args[2]); if ($extMsg !== null) { $extParams = $this->parseExtParams($args[3]); if ($extParams !== null) { $args[3] = vsprintf($extMsg, $extParams); } else { - $this->logger?->error("Could not parse chat notice", [ - "packet" => $args, + $this->logger?->error('Could not parse chat notice', [ + 'packet' => $args, ]); } } @@ -86,9 +86,9 @@ public function parseBinaryPackage(BinaryPackage $package): Package { } else { assert($result instanceof OutPackage); } - $this->logger?->debug("Parsed {binary_package} into {package}", [ - "binary_package" => $package, - "package" => $result, + $this->logger?->debug('Parsed {binary_package} into {package}', [ + 'binary_package' => $package, + 'package' => $result, ]); return $result; } @@ -123,7 +123,7 @@ private function readExtendedMessage(string $msg): ?ExtendedMessage { $origMessage = $msg; $message = ''; - while (substr($msg, 0, 2) === "~&") { + while (substr($msg, 0, 2) === '~&') { // remove header '~&' $msg = substr($msg, 2); @@ -134,9 +134,9 @@ private function readExtendedMessage(string $msg): ?ExtendedMessage { $messageString = null; if ($args === null) { $this->logger?->warning("Error parsing parameters for category '{category}', instance '{instance}' string '{message}'", [ - "category" => $category, - "instance" => $instance, - "message" => $msg, + 'category' => $category, + 'instance' => $instance, + 'message' => $msg, ]); } else { $messageString = $this->mmdb->getMessageString($category, $instance); @@ -152,9 +152,9 @@ private function readExtendedMessage(string $msg): ?ExtendedMessage { category: $category ?? 0, instance: $instance ?? 0, message: $message, - messageString: $messageString ?? "", + messageString: $messageString ?? '', ); - $this->logger?->debug("Extended message {message} composed", ["message" => $extMessage]); + $this->logger?->debug('Extended message {message} composed', ['message' => $extMessage]); return $extMessage; } @@ -171,36 +171,36 @@ private function parseExtParams(string &$msg): ?array { $dataType = $msg[0]; $msg = substr($msg, 1); // skip the data type id switch ($dataType) { - case "S": + case 'S': $len = ord($msg[0]) * 256 + ord($msg[1]); $str = substr($msg, 2, $len); $msg = substr($msg, $len + 2); $args[] = $str; break; - case "s": + case 's': $len = ord($msg[0]); $str = substr($msg, 1, $len - 1); $msg = substr($msg, $len); $args[] = $str; break; - case "I": - $array = unpack("N", $msg); + case 'I': + $array = unpack('N', $msg); if (!is_array($array)) { - throw new \Exception("Invalid packet data received."); + throw new \Exception('Invalid packet data received.'); } $args[] = $array[1]; $msg = substr($msg, 4); break; - case "i": - case "u": + case 'i': + case 'u': $num = $this->b85g($msg); $args[] = $num; break; - case "R": + case 'R': $cat = $this->b85g($msg); $ins = $this->b85g($msg); $str = $this->mmdb->getMessageString($cat, $ins); @@ -210,13 +210,13 @@ private function parseExtParams(string &$msg): ?array { $args[] = $str; break; - case "l": - $array = unpack("N", $msg); + case 'l': + $array = unpack('N', $msg); if (!is_array($array)) { - throw new \Exception("Invalid packet data received."); + throw new \Exception('Invalid packet data received.'); } $msg = substr($msg, 4); - $cat = 20000; + $cat = 20_000; $ins = $array[1]; $str = $this->mmdb->getMessageString($cat, $ins); if ($str === null) { @@ -225,13 +225,13 @@ private function parseExtParams(string &$msg): ?array { $args[] = $str; break; - case "~": + case '~': // reached end of message break 2; default: $this->logger?->warning("Unknown data type '{data_type}'", [ - "data_type" => $dataType, + 'data_type' => $dataType, ]); return null; } @@ -266,7 +266,7 @@ private function b85g(string &$str): int { private function orderArgs(string $class, null|bool|int|string|ExtendedMessage|array|Group\GroupId ...$args): array { $orderedArgs = []; $refClass = new \ReflectionClass($class); - $refFunc = $refClass->getMethod("__construct"); + $refFunc = $refClass->getMethod('__construct'); $refParams = $refFunc->getParameters(); $pos = 0; foreach ($refParams as $refParam) { @@ -286,93 +286,93 @@ private function orderArgs(string $class, null|bool|int|string|ExtendedMessage|a /** @return list */ private function parseFormat(string $format, string $data): array { - if ($format === "") { + if ($format === '') { return []; } - $this->logger?->debug("Parsing AO binary format {format}", ["format" => $format]); + $this->logger?->debug('Parsing AO binary format {format}', ['format' => $format]); switch (substr($format, 0, 1)) { - case "B": - $unp = unpack("Nnumber", $data); - $this->logger?->debug("Parsed bool {value}", ["value" => $unp['number'] ? "true" : "false"]); + case 'B': + $unp = unpack('Nnumber', $data); + $this->logger?->debug('Parsed bool {value}', ['value' => $unp['number'] ? 'true' : 'false']); return [ (bool)$unp['number'], ...$this->parseFormat(substr($format, 1), substr($data, 4)), ]; - case "I": - $unp = unpack("Nnumber", $data); - $this->logger?->debug("Parsed int {value}", ["value" => $unp['number']]); + case 'I': + $unp = unpack('Nnumber', $data); + $this->logger?->debug('Parsed int {value}', ['value' => $unp['number']]); return [ $unp['number'], ...$this->parseFormat(substr($format, 1), substr($data, 4)), ]; - case "S": - $unp = unpack("nlength", $data); + case 'S': + $unp = unpack('nlength', $data); $len = $unp['length']; - $this->logger?->debug("Parsed string length {length}: {value}", [ - "length" => $unp['length'], - "value" => new MaybeBinaryString(substr($data, 2, $len)), + $this->logger?->debug('Parsed string length {length}: {value}', [ + 'length' => $unp['length'], + 'value' => new MaybeBinaryString(substr($data, 2, $len)), ]); return [ substr($data, 2, $len), ...$this->parseFormat(substr($format, 1), substr($data, 2 + $len)), ]; - case "G": - $unp = unpack("Ctype/Nid", $data); - $this->logger?->debug("Parsed group type={type}, id={id}", [ - "type" => $unp['type'], - "id" => $unp['id'], + case 'G': + $unp = unpack('Ctype/Nid', $data); + $this->logger?->debug('Parsed group type={type}, id={id}', [ + 'type' => $unp['type'], + 'id' => $unp['id'], ]); return [ new Group\GroupId(type: $unp['type'], number: $unp['id']), ...$this->parseFormat(substr($format, 1), substr($data, 5)), ]; - case "i": - $unp = unpack("nlength", $data); + case 'i': + $unp = unpack('nlength', $data); $len = $unp['length']; - $this->logger?->debug("Parsed int[] length {length}", ["length" => $len]); - $unp = unpack("N" . $len, substr($data, 2)); + $this->logger?->debug('Parsed int[] length {length}', ['length' => $len]); + $unp = unpack('N' . $len, substr($data, 2)); /** @var int[] */ $res = array_values($unp); - $this->logger?->debug("Parsed int[] length {length}, values {values}", [ - "length" => $len, - "values" => $res, + $this->logger?->debug('Parsed int[] length {length}, values {values}', [ + 'length' => $len, + 'values' => $res, ]); return [ $res, ...$this->parseFormat(substr($format, 1), substr($data, 2 + 4 * $len)), ]; - case "b": - $unp = unpack("nlength", $data); + case 'b': + $unp = unpack('nlength', $data); $len = $unp['length']; - $this->logger?->debug("Parsed bool[] length {length}", ["length" => $len]); - $unp = unpack("N" . $len, substr($data, 2)); + $this->logger?->debug('Parsed bool[] length {length}', ['length' => $len]); + $unp = unpack('N' . $len, substr($data, 2)); /** @var bool[] */ $res = array_map(boolval(...), array_values($unp)); - $this->logger?->debug("Parsed bool[] length {length}, values {values}", [ - "length" => $len, - "values" => array_map(fn (bool $val): string => $val ? "true" : "false", $res), + $this->logger?->debug('Parsed bool[] length {length}, values {values}', [ + 'length' => $len, + 'values' => array_map(static fn (bool $val): string => $val ? 'true' : 'false', $res), ]); return [ $res, ...$this->parseFormat(substr($format, 1), substr($data, 2 + 4 * $len)), ]; - case "s": - $unp = unpack("nlength", $data); + case 's': + $unp = unpack('nlength', $data); $arrayLength = $len = $unp['length']; - $this->logger?->debug("Parsed string[] length {length}", ["length" => $len]); + $this->logger?->debug('Parsed string[] length {length}', ['length' => $len]); $data = substr($data, 2); $res = []; while ($len--) { - $unp = unpack("nstrlen", $data); + $unp = unpack('nstrlen', $data); $slen = $unp['strlen']; $res []= substr($data, 2, $slen); $data = substr($data, 2+$slen); } - $this->logger?->debug("Parsed string[] length {length}, values {values}", [ - "length" => $arrayLength, - "values" => $res, + $this->logger?->debug('Parsed string[] length {length}, values {values}', [ + 'length' => $arrayLength, + 'values' => $res, ]); return [ $res, diff --git a/src/Tokenizer.php b/src/Tokenizer.php index ce74041..ca14593 100644 --- a/src/Tokenizer.php +++ b/src/Tokenizer.php @@ -28,10 +28,10 @@ public function __construct( public function read(?Cancellation $cancellation=null): ?string { try { $binHeader = $this->reader->readLength(4, $cancellation); - $header = unpack("ntype/nlength", $binHeader); + $header = unpack('ntype/nlength', $binHeader); assert(is_int($header['length'])); assert($header['length'] >= 0); - $binBody = ""; + $binBody = ''; if ($header['length'] > 0) { $binBody = $this->reader->readLength($header['length'], $cancellation); } diff --git a/src/Utils.php b/src/Utils.php index 86a8513..8f59d41 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -16,13 +16,13 @@ public static function normalizeCharacter(string $character): string { } public static function closureToString(Closure $closure): string { - $result = ""; + $result = ''; $refCallback = new ReflectionFunction($closure); $class = $refCallback->getClosureCalledClass(); $function = $refCallback->getShortName(); if (isset($class)) { $result .= $class->getName(). - (($refCallback->isStatic()) ? "::" : "->"). + (($refCallback->isStatic()) ? '::' : '->'). $function; } else { if (!$refCallback->inNamespace()) { @@ -30,8 +30,8 @@ public static function closureToString(Closure $closure): string { } $result .= $function; } - if (!str_ends_with($function, "}")) { - $result .= "()"; + if (!str_ends_with($function, '}')) { + $result .= '()'; } $fileName = $refCallback->getFileName(); if ($fileName !== false) { @@ -40,7 +40,7 @@ public static function closureToString(Closure $closure): string { if ($startLine !== false) { $result .= ":{$startLine}"; } - $result .= ")"; + $result .= ')'; } return $result; } diff --git a/tests/MMDBTest.php b/tests/MMDBTest.php index 3623edb..75a9eab 100644 --- a/tests/MMDBTest.php +++ b/tests/MMDBTest.php @@ -3,7 +3,7 @@ namespace AO\Tests; use function Amp\File\openFile; -use AO\MMDB\AsyncClient; +use AO\MMDB\AsyncMMDBClient; use Beste\Psr\Log\TestLogger; use Exception; @@ -13,22 +13,22 @@ final class MMDBTest extends TestCase { public function testException(): void { $this->expectException(Exception::class); - new AsyncClient( + new AsyncMMDBClient( logger: TestLogger::create(), - mmdb: openFile(__FILE__, "rb"), + mmdb: openFile(__FILE__, 'rb'), ); } /** @return list */ public static function exampleMMDBTexts(): array { return [ - [20000, 18838393, "Removing %d #1{ 1:buddy | buddies }."], + [20_000, 18_838_393, 'Removing %d #1{ 1:buddy | buddies }.'], ]; } #[DataProvider('exampleMMDBTexts')] public function testMessages(int $categoryId, int $messageId, string $expected): void { - $mmdb = AsyncClient::createDefault(); + $mmdb = AsyncMMDBClient::createDefault(); $this->assertSame($expected, $mmdb->getMessageString($categoryId, $messageId)); } }